I've just come across a situation in the app I'm working in, in which I wrote an action specifically for setting the language cookie and redirect to the last url. Something like this:
def language
cookies[:locale] = {:value => params[:locale], :domain => APP_DOMAIN}
redirect_to_back
end
Thing is, I'm not very pleased with this. Since the whole purpose of the endpoint is to set a new language for the app on the server side, this super-light logic kind of gets jammed in the whole middleware stack before it actually reaches the controller, which hurts the performance of the workflow. But later, I found out I could redirect straight from the route mapper (http://guides.rubyonrails.org/routing.html#redirection), and thought I had found the solution to all my problems.
match "language/:locale" => redirect {|p, req| req.cookies["locale"] = {:value => p[:locale], :domain => APP_DOMAIN} ; req.referrer || '' }
Problem is, Even though I have access to the request, and can therefore insert cookies in it, only the last value of the redirect block will be taken to form the redirection response. Which will not check the request and set its cookies (or whatever more there may be) accordingly. So yeah, the question is, does anybody know a way of influencing the route.rb redirections a bit more than by passing the destination route?
And no, I don't want a client-side solution. I'm fully aware I can also do this with JS, I just wanted a no-JS solution.
Thanks in advance