Combining Devise with resources :users in Rails

前端 未结 3 458
孤独总比滥情好
孤独总比滥情好 2020-12-16 13:47

I am trying to combine Devise with a RESTful user resource using the following code in the routes.rb file:

resources :users, :only => [:index, :show]
devi         


        
3条回答
  •  天涯浪人
    2020-12-16 14:15

    My advice in these situations is to check with rake routes In routes the order in which routes are defined matters since earlier routes take precedence.

    So in your case resources :users, :only => [:index, :show] created a restfull /users/:id(.:format) route that pointed to {:action=>"show", :controller=>"users"} and when you went to Devise's sign up url /users/sign-up it considered 'sign-up' an :id of the user and naturally couldnt find it.

    Now if you do the devise routing setup first, devise's routes take precedence over anything specified later and you get expected behaviour.

提交回复
热议问题