Answer the question
In order to leave comments, you need to log in
How to properly reorder named routes in rails 4?
Hello.
There is an application on rails. And the main site running this application. All links on this site are without CNC.
We make a personal website for one of our clients based on our application (the design is his own, the functionality is ours).
The client's desire is to have CNC links. It is not possible to change links globally, as they are also used outside of our site. Ok, we create duplicates of our routes using the prefix. That is, there was a route named index, a new one appeared with the name clientname_index, and so on.
But many actions use helper calls for named routes. Putting conditions everywhere about which helper to call - it smells like a collective farm :)
Therefore, it was decided to add the following construction to application_controller:
def set_template_and_vars
if '%clients_domain%' == request.host
params[:template] = 'clients_template'
%w(index project ...куча других имен маршрутов).each do |name|
self.class.send('define_method', ("#{name}_path")) { |arguments| send("clientname_#{name}_path", arguments) }
end
end
end
Answer the question
In order to leave comments, you need to log in
Set conditions everywhere about which helper to call - it smells like a collective farm :)
Please, at least in Rails, don't port this CNC machine.
What is the problem? Have you heard
about this method ? Does not help?
And also about globs and constraints ?
Write what you want to achieve and why you can't do it with the standard Rails methods
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question