What is the best way to deal with Vanity URL Helpers in Rails 3?

I have a web application that I work with Rails 3, and I just implemented some basic Vanity URL paths to existing application resources. What I want to do is not to try to explicitly build the URLs on the user profile page for available resources, for example. I would like to be able to create a URL with link_to in a view in the format:

typealoud.com/:user_id/:thread_id/:comment_id

And not what the standard nested resource helpers give me, for example:

typealoud.com/threads/:thread_id/comments/:comment_id

Should I do it myself as a URL helper or is there an existing stone?

+3
source share
1 answer

To do this, I would put this at the top of my routes:

match ':user_id/:thread_id/:id', :to => "comments#show"

comment_id id, "Rails Way", id id. .

, :as:

match ':user_id/:thread_id/:id', :to => "comments#show", :as => "comment"

comment_path/comment_url , , .

+3

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


All Articles