开发者

How do I customize the user registration route with the devise gem for Rails?

I use the Devise gem with Rails and would like to alter the action that occurs during user registration. My faulty customization looks like this:

devise_for :users,  :controllers => { :registrations 开发者_如何转开发=> "users/registrations" } do
    post "/", :to => "users/registrations#create_from_admin"
  end

Resulting in this:

[bbrasky@admins-MacBook-Pro-2:~/Projects/my_app(master)]$ rake routes
POST   /users(.:format) {:controller=>"users/registrations", :action=>"create"}

Does anyone know how to do this?

Thanks!


Here is what I was able to do with the Devise routes to customize all of them

devise_for :users, :as => "", :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" } 

match "login" => "devise/sessions#new", :as => :new_user_session 
match "logout" => "devise/sessions#destroy", :as => :destroy_user_session
match "register" => "devise/registrations#new", :as => :new_user_registration

If you run rake routes you will see the rest that you could modify but this is the start of the list and they all work correctly :) Have fun!


Tried the approach above with the latest version of rails 4 and devise and it didn't work for me, but found the solution in the documentation here with configuring routes. Similar approach but using the devise_scope within the routes file instead of match. Hope it helps someone else.

 devise_for :users, :path_names => { :sign_in => "login", :sign_out => "logout", :sign_up => "register" } 

 devise_scope :user do
  get "login", to: "devise/sessions#new"
  get "logout", to: "devise/sessions#destroy"
  get "register", to: "devise/registrations#new"
 end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜