In the Tail

Exploring the niche consumer

Permalinks in Rails

I was looking into different search engine optimization techniques (SEO) and one of the things they said were that search engines filter some links based on http get arguments. If you have a link like http://www.secretfalls.com/trails/show?1, it might not index that page. Well in Rails that shouldn’t be an issue, because the way the controller works, you get the identifier as part of the http URL, so the above example would be http://www.secretfalls.com//trails/show/1 which is better, but it would still be nicer to have http://www.secretfalls.com//trails/show/Hickey_Gap_Trail.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class HikingController < ApplicationController
  before_filter :common
  def common
     @states = State.find_states
  end
  def index
    @trails = Trail.find_trails
  end
  def show
    @trail =Trail.find(params[ :id ])
  end
  def show_by_state
    @trails =Trail.find_by_state(params[ :id ])
  end
end

I was going to do a big write up here, but like so many things in rails I found that someone had already doe exactly what I wanted. Take a look at SEO for Ruby on Rails This plugin acts_as_friendly_param is super easy and gives you nice seo friendly URL’s