ruby-on-rails – redirect_to current_user with params

如何将参数传递给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

比如结果URL就像foo.com/?param1=’bubbles’.令人困惑的是,我将STI用于不同类型的用户,因此每个用户类型都有自己的“show”url,所以这样的方法

redirect_to controller: 'thing', action: 'edit', id: 3, something: 'else'

不起作用,因为每个用户类型都有自己的控制器.

最佳答案 您可以使用

redirect_to  polymorphic_path(current_user, something:'else')
点赞