[英]redirect_to current_user with params
How can I pass parameters to my current_user redirect? 如何将参数传递给current_user重定向?
# SessionHelper.rb
def current_user
if(user_id = session[:user_id])
@current_user ||= User.find(user_id)
else
@current_user = nil
end
end
#SomeController.rb
def some_action
redirect_to current_user, param1: "bubbles"
end
# routes.rb
resources :doctors, :admins, :agencies # this is the line that handles current_user path
Such as resulting URL would be like foo.com/?param1='bubbles'. 比如结果URL就像foo.com/?param1='bubbles'。 The confusing thing here is, I use STI for different types of users, so every user type has its own 'show' url, so a approach like this
令人困惑的是,我将STI用于不同类型的用户,因此每个用户类型都有自己的“show” url,所以这样的方法
redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'
would not work, since every user type has its own controller. 不起作用,因为每个用户类型都有自己的控制器。
您可以使用
redirect_to polymorphic_path(current_user, something:'else')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.