The best permanent challenge for rails

What is the best way to create SEO friendly URLs (dynamically) in Rails?

+4
source share
7 answers

Override the to_param method in your model classes to replace the default numeric identifier with a meaningful string. For example, this question uses the best-permalinking-for-rails URL.

Ryan Bates has a Railscast in this section .

+6
source

ActiveSupport has a new method in Rails to help this โ€” the String # parameterize parameter. Appropriate commit here ; an example cited in a commit message is Donald E. Knut .parameterize => "donald-e-knuth"

Combined with the to_param redefinition mentioned by John Topley, this simplifies friendly URLs.

+3
source

rsl stringex is pretty cool, think that permalink_fu is done right.

+2
source

I mainly use to_param as suggested by John Tolly.

Remember to put the indexes so that everything you use in to_param is quickly searchable, or you get a full table scan for each access. ( Not a performance enhancer!)

The quick work is to set the identifier somewhere out there, in which case ActiveRecord will ignore the rest of this file as cracks and just search by identifier. That's why you see a lot of Rails sites with URLs like http://example.com/someController/123-a-half-readable-title .

For more on this and other SEO observations from my experience with Rails, you can find this page on my website.

+2
source

Friendly_id works fine for me, it can also generate bullets, so you donโ€™t need to consider duplicate URLs, areas are also supported.

+1
source

Check out the permalink_fu plugin (extracted from Mephisto) ... the Git repository located here .

0
source

I made a small and simple stone that simplifies the redefinition of the to_param method. You can find it here.

0
source

Source: https://habr.com/ru/post/1276819/


All Articles