Redirect_to current_user with parameters

How to pass parameters to current_user redirection?

# 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 a resulting URL would look like foo.com/?param1='bubbles. The tricky thing here, I use STI for different types of users, so each user type has its own 'show' url, so this approach

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

will not work, since each user type has its own controller.

+4
source share
1 answer

you can use

redirect_to  polymorphic_path(current_user, something:'else')
+2
source

Source: https://habr.com/ru/post/1627785/


All Articles