I need to add the params sort
to all my links if it exists.
Solutions I have in mind:
Using link_to.. Not convenient and I think it is ugly.
link_to 'Something', tag_url(tags, params.except(:controller, :action))
Create custom link helper
Owerwrite link_to helper (Have tried without success)
What is best practice?
Update:
def link_to_with_params(*args, &block)
if block_given?
options = args.first || {}
html_options = args.second
link_to(capture(&block), options, html_options)
else
name = args[0]
options = args[1] || {}
html_options = args[2]
html_options = convert_options_to_data_attributes(options, html_options)
url = url_for(options) # Add params.except(:controller, :action)
href = html_options['href']
tag_options = tag_options(html_options)
href_attr = "href=\"#{ERB::Util.html_escape(url))}\"" unless href
"<a #{href_attr}#{tag_options}>#{ERB::Util.html_escape(name || url)}</a>".html_safe
end
end
How do I pass params.except(:controller, :action)
to the url in the helper above?