Reputation: 22565
Is it possible to route a request depending on a session value?
I would like to route /test
to test#withoutsession
or /test
to test#withsession
depending on a session value.
Upvotes: 2
Views: 76
Reputation: 29291
Your best bet is probably applying dynamic constraints to your routes, like this:
get '/test', :to => 'test#withoutsession', :constraints => lambda{ |req| req.session[:user_id].blank? }
get '/test', :to => 'test#withsession', :constraints => lambda{ |req| req.session[:user_id].present? }
Reference: http://edgeguides.rubyonrails.org/routing.html#advanced-constraints
Upvotes: 1