How can I redirect multiple development models to multiple specific URLs?

I have three independent designer models, I got three different sign_in screens. And all three have a dashboard:

devise_for :md1 devise_for :md2 devise_for :md3 match 'md1/dashboard' => 'md1#dashboard', :via => :get match 'md2/dashboard' => 'md2#dashboard', :via => :get match 'md3/dashboard' => 'md3#dashboard', :via => :get 

I want it to be redirected to the mdX # control panel upon successful login to mdX, and if possible, GET. I tried:

 devise_scope :md1 do root :to => 'md1#dashboard' end devise_scope :md2 do root :to => 'md2#dashboard' end devise_scope :md3 do root :to => 'md3#dashboard' end 

Then, when I successfully enter md1, I am redirected to the md1 control panel, but when I successfully enter md2, I am redirected to the md1 sign_in screen. Then I tried:

 def after_sign_in_path_for resource dashboard_path resource end 

But there is no such method. Is there an easy way to do this or should it be with if for each model?

UPDATE

Some routes to better understand and get more information to get a better solution.

 md1_dashboard GET /md1/dashboard(.:format) md1#dashboard md2_dashboard GET /md2/dashboard(.:format) md2#dashboard md3_dashboard GET /md3/dashboard(.:format) md3#dashboard 

thanks in advance

+4
source share
1 answer

When you write this:

 devise_scope :md1 do root :to => 'md1#dashboard' end devise_scope :md2 do root :to => 'md2#dashboard' end devise_scope :md3 do root :to => 'md3#dashboard' end 

You define three root routes with the same name. Since they conflict, only the first will be used. That's why only md1 worked. You would probably like to write this:

 scope :md1 do root :to => 'md1#dashboard' end scope :md2 do root :to => 'md2#dashboard' end scope :md3 do root :to => 'md3#dashboard' end 

In this case, you define three different root routes in three different areas (check rake routes again). Note scope is a router method that spans routes, devise_scope has no route, it just tells you which development area you want to use, which you don't need to tell if Devise explicitly asks you (you'll know when this will happen).

After this change, everything should work as expected. Note that Devise by default uses #{scope}_root_path to redirect after a successful login, so the above code works (check rake routes and you will see that you are md1_root , md2_root , etc.).

+6
source

All Articles