Sohan
Sohan

Reputation: 3807

How to create search engine friendly url for rails models?

I looked into this plugin called acts_as_permalinkable at github and found it to be useful. Do you know of any other plugin that generates search engine friendly urls for ruby on rails models in a better way?

Upvotes: 1

Views: 376

Answers (3)

pjammer
pjammer

Reputation: 9577

there is always just to_params in your model which can display basically whatever you want. Just note that your methods in that model will have to change, when you use find.

e.g. in the post.rb file

def to_param
  name.parameterize
end

and in your posts_controller.rb methods that usually pick up the params[:id] call, you just have to change them to:

@post = Post.find_by_name(params[:id])

no plugin, no fuss and still pretty urls.

Upvotes: 0

nowk
nowk

Reputation: 33161

friendly_id might do the trick for you.

Upvotes: 2

Adam Crossland
Adam Crossland

Reputation: 14213

acts_as_urlnameable does the trick as well. I haven't used permalinkable, so I can't say that it is better. Does it have some specific deficiencies that concern you?

It lives at: http://code.helicoid.net/svn/rails/plugins/acts_as_urlnameable/

Upvotes: 0

Related Questions