How to implement “short” nested vanity urls in rails?

Take a look at the Rails Routing from the Outside In guide.

That's what I've been reading, but I can't seem to grasp from the available examples and descriptions what should lead to the results I'm looking for. Is it shallow nesting? :has_many?

Or using map. Connect and wildcards (which some people say you shouldn't use)... kinda looking for a hint into the right direction here. – UnSandpiper Apr 4 '10 at 19:11.

To have this work "nicely" with the Rails URL helpers you have to override to_param in your model: def to_param permalink end Where permalink is generated by perhaps a before_save before_save :set_permalink def set_permalink self. Permalink = title. Parameterize end The reason you create a permalink is because, eventually, maybe, potentially, you'll have a title that is not URL friendly.

That is where parameterize comes in. Now, as for finding those posts based on what permalink is you can either go the easy route or the hard route. Easy route Define to_param slightly differently: def to_param id.

To_s + permalink end Continue using Forum. Find(params:id) where params:id would be something such as 1-my-awesome-forum. Why does this still work?

Well, Rails will call to_i on the argument passed to find, and calling to_i on that string will return simply 1. Hard route Leave to_param the same. Resort to using find_by_permalink in your controllers, using params:id which is passed in form the routes: Model.

Find_by_permalink(params:id) Now for the fun part Now you want to take the resource out of the URL. Well, it's a Sisyphean approach. Sure you could stop using the routing helpers Ruby on Rails provides such as map.

Resources and define them using map. Connect but is it really worth that much gain? What "special super powers" does it grant you?

None, I'm afraid. But still if you wanted to do that, here's a great place to start from: get ':forum_id/:board_id/:topic_id', :to => "topics#show", :as => "forum_board_topic.

Maybe try something like map. My_thread ':forum_id/:board_od/:thread_id. :format', :controller => 'threads', :action => 'show' And then in your controller have @forum = Forum.

Find(params:forum_id) @board = @forum. Find(params:board_id) @thread = @board. Find(params:thread_id) Notice that you can have that model_id be anything (the name in this case) In your view, you can use I hope this helps.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions