Home Ask Login Register

Developers Planet

Your answer is one click away!

Burak Özmen February 2016

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)
        @current_user = nil

def some_action
   redirect_to current_user, param1: "bubbles"

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


Vasfed February 2016

You can use

redirect_to  polymorphic_path(current_user, something:'else')

Post Status

Asked in February 2016
Viewed 2,234 times
Voted 6
Answered 1 times


Leave an answer

Quote of the day: live life