addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcredit-cardcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Arlington Ruby Message Board › Friendly URL

Friendly URL

Yungchih C.
user 69650282
Arlington, VA
Post #: 1
Does anyone knows how to create friendly URL by configure router.rb and not using friendly_id gem or to_param method?

Thank you in advance
Sean M.
SeanMarcia
Arlington, VA
Post #: 14
Did you find any way other than to_param?
LisaSchaefer PhD C...
CrowdPublish.TV
Phoenix, AZ
Post #: 28
Are you looking for something auto-generated (as the friendlyid gem does), or user-supplied (like a permalink http://railscasts.com...­ Either way, you have to override to_param. Or are you looking to create subdomains http://guides.rubyonr...­
Yungchih C.
user 69650282
Arlington, VA
Post #: 2
Did you find any way other than to_param?
Sean, No I have not, but my friend told me that it can be done by configure the route that is like /some/:route/:with_info then :route and :with_info are in your params hash, when that route matches and your controller is called.
I am still new to ruby, don't know if you know how to do that

Thanks
Dave A.
davearonson
Fairfax, VA
Post #: 93
You can also substitute what you consider to be the "id". On one of my current projects, we've got (nested) routes set up using the standard Rails "resources" keyword in config/routes.rb, but what we accept as the "id" is not only not a number, it's not even what we have in the "id" column of the database tables (which is a number as usual). In most cases, it's a name. In the controllers, we just have to remember to do Widget.find_by_name rather than Widget.find.

It MUST be something that Rails will recognize as a unit and put there. I recommend you require that it be composed only of letters, numbers, and dashes, no other special chars. Dots in particular will confuse Rails, as I found out when trying to do this trick with users' email addresses. I am not sure about spaces; we have other reasons to heavily restrict the characters anyway, to make the names "DNS friendly" or in some cases at least "URL friendly".

For instance we have urls like /widgets/foo-bar/extensions/baz-quux, so Rails will hand us "foo-bar" as the widget_id and "baz-quux" as the id, of the extension we're currently trying to retrieve. However, /users/joe.shmoe@kokomo.com is right out -- and apparently CGI::escape'ing it won't fix it to Rails's satisfaction.
Powered by mvnForum

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy