How do I remove the model name from Devise urls?
Ie
users/sign_in -> /sign_in
users/sign_out -> /sign_out
users/registration/sign_up -> /sign_up
users/registration/edit -> 开发者_JAVA技巧/edit
This is covered in the devise README (https://github.com/plataformatec/devise):
Devise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:
devise_for :users, :path => "usuarios", :path_names => { :sign_in => 'login', :sign_out => 'logout', :password => 'secret', :confirmation => 'verification', :unlock => 'unblock', :registration => 'register', :sign_up => 'cmon_let_me_in' }
Be sure to check devise_for documentation for details.
If you have the need for more deep customization, for instance to also allow "/sign_in" besides "/users/sign_in", all you need to do is to create your routes normally and wrap them in a devise_scope block in the router:
devise_scope :user do
get "sign_in", :to => "devise/sessions#new"
end
This way you tell devise to use the scope :user when "/sign_in" is accessed. Notice devise_scope is also aliased as as and you can also give a block to devise_for, resulting in the same behavior:
devise_for :users do
get "sign_in", :to => "devise/sessions#new"
end
Feel free to choose the one you prefer!
(Maybe this wasn't in the README when this question was originally posed.)
The way to do this manually is Rails 3 would be:
match 'sign_in' => 'devise/sessions#new', :as => :sign_in
match 'sign_out' => 'devise/sessions#destroy', :as => :sign_out
精彩评论