2

是否可以根据会话值路由请求?

我想根据会话值路由/testtest#withoutsession/test到。test#withsession

4

1 回答 1

1

您最好的选择可能是对您的路线应用动态约束,如下所示:

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? }

参考:http ://edgeguides.rubyonrails.org/routing.html#advanced-constraints

于 2013-06-20T01:22:31.423 回答