I am wondering if there is a way to extend the existing path helpers that Rails created for my routes.
I have something like /videos/view/:id already and now I need to append a tag parameter to that link wherever it (from the current params collection).
The only solution I see right now is to go through all the views and change the call to the helper to look like this:
view_videos_path(video, tag: params[:tag])
Now obviously that’s a bit of work and a much easier way to do this would be to just overwrite the existing path helper with something like this:
def view_videos_path(video, opts)
view_videos_path(video, opts.merge(tag: params[:tag]))
end
Obviously putting this in a module would result in a endless recursion so I wonder if there is any best practice on how to do this.
Also, what do you think of the approach? I am not really sure if extending the helper like this is wise or not. But to me at the moment it looks reasonable.
Throw them in a helper module and call
super, you can also include it intoApplicationControllerso the paths are also available in your controllers: