mah*_*off 7 routes ruby-on-rails devise ruby-on-rails-3
有没有办法在routes.rb中访问当前用户?我想要这样的映射:
match /profile => redirect("/profiles/{current_user.name}")
Run Code Online (Sandbox Code Playgroud)
env['warden']似乎没有设置,所以我无法访问warden.user.name.
不确定是否可能.但是,您可以使用控制器:
def profile
if signed_in?
redirect_to user_profile_path(current_user)
else
redirect_to root_url
end
end
Run Code Online (Sandbox Code Playgroud)
要扩展user1136228的答案:
get '/profile', to: redirect { |params, request|
me = request.env["warden"].user(:user)
me ? ('/profiles/' + me.name) : '/'
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2932 次 |
| 最近记录: |