Burak Özmen
Burak Özmen

Reputation: 873

redirect_to current_user with params

How can I pass parameters to my current_user redirect?

# 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'. 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

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

would not work, since every user type has its own controller.

Upvotes: 4

Views: 405

Answers (1)

Vasfed
Vasfed

Reputation: 18504

You can use

redirect_to  polymorphic_path(current_user, something:'else')

Upvotes: 2

Related Questions