Combining Devise with resources :users in Rails

前端 未结 3 456
孤独总比滥情好
孤独总比滥情好 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.

    0 讨论(0)
  • 2020-12-16 14:17

    Yes, that's the right way to do it (see https://github.com/plataformatec/devise/wiki/How-To:-Manage-users-through-a-CRUD-interface)

    0 讨论(0)
  • 2020-12-16 14:18

    In the link David Sulc wrote is shown that you should write a prefix to device_for or resources Example:

    devise_for :users, :path_prefix => 'my'
    resources :users
    

    Or your users

    devise_for :users
    scope "/admin" do
      resources :users
    end
    

    Both works well for me

    0 讨论(0)
提交回复
热议问题