在我的编辑个人资料页面
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
在我的路线
devise_for :users,
:controllers => {
:registrations => "registrations",
:sessions => "sessions",
:invitations => 'invitations'
},
:path => '/',
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:sign_up => 'signup'
}
devise_scope :user do
root :to => "registrations#new"
get '/me/profile' => 'registrations#edit', :as => "myprofile"
get "/me/invites" => 'invitations#new', :as => 'myinvites'
end
rake routes:
new_user_session GET /login(.:format) {:action=>"new", :controller=>"sessions"}
user_session POST /login(.:format) {:action=>"create", :controller=>"sessions"}
destroy_user_session DELETE /logout(.:format) {:action=>"destroy", :controller=>"sessions"}
cancel_user_registration GET /cancel(.:format) {:action=>"cancel", :controller=>"registrations"}
user_registration POST / {:action=>"create", :controller=>"registrations"}
new_user_registration GET /signup(.:format) {:action=>"new", :controller=>"registrations"}
edit_user_registration GET /edit(.:format) {:action=>"edit", :controller=>"registrations"}
PUT / {:action=>"update", :controller=>"registrations"}
DELETE / {:action=>"destroy", :controller=>"registrations"}
root / {:controller=>"registrations", :action=>"new"}
myprofile GET /me/profile(.:format) {:controller=>"registrations", :action=>"edit"}
现在,当我加入:path => '/'
时,我的编辑用户个人资料页面不再有效。单击“更新配置文件”不会更新我的用户配置文件。
编辑用户个人资料表单现在是action = '/'
(不起作用),而不是之前action = '/users'
(正常)
答案 0 :(得分:0)
我相信
...,
:controllers => {
:registrations => "registrations",
:sessions => "sessions",
:invitations => 'invitations'
},
:path => '/',
:path_names => {
:sign_in => 'login',
:sign_out => 'logout',
:sign_up => 'signup'
}
不需要。您只需要devise_for :users
作为stated in the README.rdoc
希望这有帮助。
答案 1 :(得分:0)
部分在the Devise Github Wiki上描述了设置自定义设计路线。
然而,删除映射(在本例中为“user”)并不完全清楚。
描述的:path => ''
也打破了东西。
所以,如果你想:
/sign_in
代替/users/sign_in
,
/register
代替/users/register
,
等。
你能做什么:
为会话和注册创建自定义控制器。 在这些控制器集中:
class Users::RegistrationsController < Devise::RegistrationsController
prepend_before_filter :set_devise_mapping
private
def set_devise_mapping
request.env["devise.mapping"] ||= Devise.mappings[:user]
end
end
(Users::SessionsController < Devise::SessionsController
相同)
接下来将以下内容添加到routes.rb:
devise_for :users,
:skip => [:sessions, :registrations],
:controllers => {
:omniauth_callbacks => 'users/omniauth_callbacks',
:registrations => 'users/registrations',
:passwords => 'users/passwords',
:sessions => 'users/sessions'
},
# Setting empty path gives errors in registration_path.
# So we overwrite them here.
get 'sign_in' => 'users/sessions#new', :as => :new_user_session
post 'sign_in' => 'users/sessions#create', :as => :user_session
delete 'sign_out' => 'users/sessions#destroy', :as => :destroy_user_session
get 'register' => 'users/registrations#new', :as => :new_user_registration
post 'register' => 'users/registrations#create', :as => :user_registration
要允许帐户编辑,您应该添加自己的编辑和更新路线:
namespace :users do
resource :registration, only: [:edit, :update], path: ''
end