我使用了Devise 3.0,一切都还可以,但是因为我使用Devise 3.2.4我的路线问题很多......
使用Devise 3.0,此代码有效:
devise_for :users,
:controllers => { :registrations => "users/registrations",
:passwords => "users/passwords",
:sessions => 'users/sessions'},
:skip => [:sessions] do
get 'identification' => 'users/sessions#new', :as => :new_user_session
post 'identification' => 'users/sessions#create', :as => :user_session
get 'deconnexion' => 'users/sessions#destroy', :as => :destroy_user_session
get 'inscription' => 'users/registrations#new', :as => :new_user_registration
get 'mot-de-passe' => "users/passwords#new", :as => :new_password_user
get 'mon-compte' => "users/registrations#edit", :as => :edit_user_registration
end
devise_scope :user do
get "users/pdf", :controller => "users/registrations", :action => "pdf"
get "users/download_pdf", :controller => "users/registrations", :action => "download_pdf"
get "informations-personnelles", :controller => "users/registrations", :action => "edit_profile0", :as => "users_edit_profile0"
get "vous-et-votre-projet", :controller => "users/registrations", :action => "edit_profile1", :as => "users_edit_profile1"
get "caracteristiques-du-bien", :controller => "users/registrations", :action => "edit_profile2", :as => "users_edit_profile2"
get "details-du-bien", :controller => "users/registrations", :action => "edit_profile3", :as => "users_edit_profile3"
get "quartier", :controller => "users/registrations", :action => "edit_profile4", :as => "users_edit_profile4"
get "lieu", :controller => "users/registrations", :action => "edit_profile5", :as => "users_edit_profile5"
get "budget", :controller => "users/registrations", :action => "edit_profile6", :as => "users_edit_profile6"
get "coup-de-coeur", :controller => "users/registrations", :action => "edit_profile7", :as => "users_edit_profile7"
put "users/update_avatar", :controller => "users/registrations", :action => "update_avatar"
put "users/update_profile0", :controller => "users/registrations", :action => "update_profile0"
put "users/update_profile1", :controller => "users/registrations", :action => "update_profile1"
put "users/update_profile2", :controller => "users/registrations", :action => "update_profile2"
put "users/update_profile3", :controller => "users/registrations", :action => "update_profile3"
put "users/update_profile4", :controller => "users/registrations", :action => "update_profile4"
put "users/update_profile5", :controller => "users/registrations", :action => "update_profile5"
put "users/update_profile6", :controller => "users/registrations", :action => "update_profile6"
put "users/update_profile7", :controller => "users/registrations", :action => "update_profile7"
get "users/heating", :controller => "users/registrations", :action => "heating", :as => :heating
get "users/water_heater", :controller => "users/registrations", :action => "water_heater", :as => :water_heater
end
end
由于我使用Devise 3.2.4,我遇到了一些问题:
undefined local variable or method `destroy_user_session_path'
或者
undefined local variable or method `new_user_session_path'
我在这个问题上工作了几个小时,但我找不到好的解决方案......
rake routes
的结果是:
Prefix Verb URI Pattern Controller#Action
process_webhook POST /webhooks/process(.:format) webhooks#handle
verify_webhook GET /webhooks/process(.:format) webhooks#verify
reset_webhooks DELETE /webhooks/reset(.:format) webhooks#destroy_all
webhooks GET /webhooks(.:format) webhooks#index
POST /webhooks(.:format) webhooks#create
invitations GET /invitations(.:format) invitations#index
POST /invitations(.:format) invitations#create
new_invitation GET /invitations/new(.:format) invitations#new
edit_invitation GET /invitations/:id/edit(.:format) invitations#edit
invitation GET /invitations/:id(.:format) invitations#show
PATCH /invitations/:id(.:format) invitations#update
PUT /invitations/:id(.:format) invitations#update
DELETE /invitations/:id(.:format) invitations#destroy
authenticated_user_root GET / messages#index
authenticated_realtor_root GET / pro/users#index
unauthenticated_root GET / static_pages#home
new_customer GET /customer/new(.:format) customer#new
edit_customer GET /customer/:id/edit(.:format) customer#edit
edit_credit_card_info GET /credit_card_info/:id/edit(.:format) credit_card_info#edit
confirm_customer GET /customer/confirm(.:format) customer#confirm
confirm_credit_card_info GET /credit_card_info/confirm(.:format) credit_card_info#confirm
new_transaction GET /transactions/:product_id/new(.:format) transactions#new
confirm_transaction GET /transactions/confirm/:product_id(.:format) transactions#confirm
update_areas GET /update_areas(.:format) areas#update_areas
about_users GET /a-propos(.:format) static_pages#about
about_realtors GET /pro/a-propos(.:format) static_pages#about_realtors
how_it_works_users GET /comment-ca-marche(.:format) static_pages#how_it_works
home_realtors GET /pro(.:format) static_pages#home_realtors
how_it_works_realtors GET /pro/comment-ca-marche(.:format) static_pages#how_it_works_realtors
pricing_realtors GET /pro/abonnements(.:format) static_pages#pricing
press_users GET /espace-presse(.:format) static_pages#press
press_realtors GET /pro/espace-presse(.:format) static_pages#press_realtors
terms_users GET /conditions-utilisation(.:format) static_pages#terms
terms_realtors GET /pro/conditions-utilisation(.:format) static_pages#terms_realtors
legals_users GET /mentions-legales(.:format) static_pages#legals
legals_realtors GET /pro/mentions-legales(.:format) static_pages#legals_realtors
static_pages_home GET /static_pages/home(.:format) static_pages#home
static_pages_user_mailer GET /static_pages/user_mailer(.:format) static_pages#user_mailer
pro_users_show_partial GET /pro/users/show_partial(.:format) pro/users#show_partial
pro_users_show_complete GET /pro/users/show_complete(.:format) pro/users#show_complete
pro_search_users GET /pro/users/search_users(.:format) pro/users#search_users
load_user_profile GET /pro/users/load_user_profile/:id(.:format) pro/users#load_user_profile
new_map GET /pro/users/new_map(.:format) pro/users#new_map
new_contact GET /pro/users/new_contact/:id(.:format) pro/messages#new_contact
realtors_show GET /realtors/show(.:format) realtors#show
root GET / static_pages#home
list_cities_areas GET /areas/list_cities(.:format) areas#list_cities
list_depts_areas GET /areas/list_depts(.:format) areas#list_depts
city_areas GET /areas/city(.:format) areas#city
dept_areas GET /areas/dept(.:format) areas#dept
GET /areas/kml/:hash(.:format) areas#kml
areas GET /areas(.:format) areas#index
POST /areas(.:format) areas#create
new_area GET /areas/new(.:format) areas#new
edit_area GET /areas/:id/edit(.:format) areas#edit
area GET /areas/:id(.:format) areas#show
PATCH /areas/:id(.:format) areas#update
PUT /areas/:id(.:format) areas#update
DELETE /areas/:id(.:format) areas#destroy
list_children_children GET /children/list_children(.:format) children#list_children
add_child_children GET /children/add_child(.:format) children#add_child
children GET /children(.:format) children#index
POST /children(.:format) children#create
new_child GET /children/new(.:format) children#new
edit_child GET /children/:id/edit(.:format) children#edit
child GET /children/:id(.:format) children#show
PATCH /children/:id(.:format) children#update
PUT /children/:id(.:format) children#update
DELETE /children/:id(.:format) children#destroy
messages GET /messages(.:format) messages#index
POST /messages(.:format) messages#create
new_message GET /messages/new(.:format) messages#new
edit_message GET /messages/:id/edit(.:format) messages#edit
message GET /messages/:id(.:format) messages#show
PATCH /messages/:id(.:format) messages#update
PUT /messages/:id(.:format) messages#update
DELETE /messages/:id(.:format) messages#destroy
load_discussion GET /messages/load_discussion/:id(.:format) messages#load_discussion
faye_alive GET /messages/faye_alive/:id(.:format) messages#faye_alive
GET /invitations(.:format) invitations#index
POST /invitations(.:format) invitations#create
GET /invitations/new(.:format) invitations#new
GET /invitations/:id/edit(.:format) invitations#edit
GET /invitations/:id(.:format) invitations#show
PATCH /invitations/:id(.:format) invitations#update
PUT /invitations/:id(.:format) invitations#update
DELETE /invitations/:id(.:format) invitations#destroy
load_invitation GET /invitations/load_invitation/:id(.:format) invitations#load_invitation
pro_messages GET /pro/messages(.:format) pro/messages#index
POST /pro/messages(.:format) pro/messages#create
new_pro_message GET /pro/messages/new(.:format) pro/messages#new
edit_pro_message GET /pro/messages/:id/edit(.:format) pro/messages#edit
pro_message GET /pro/messages/:id(.:format) pro/messages#show
PATCH /pro/messages/:id(.:format) pro/messages#update
PUT /pro/messages/:id(.:format) pro/messages#update
DELETE /pro/messages/:id(.:format) pro/messages#destroy
pro_discussion_user GET /pro/discussion/:id(.:format) pro/messages#index
pro_load_discussion GET /pro/messages/load_discussion/:id(.:format) pro/messages#load_discussion
pro_users GET /pro/users(.:format) pro/users#index
POST /pro/users(.:format) pro/users#create
new_pro_user GET /pro/users/new(.:format) pro/users#new
edit_pro_user GET /pro/users/:id/edit(.:format) pro/users#edit
pro_user GET /pro/users/:id(.:format) pro/users#show
PATCH /pro/users/:id(.:format) pro/users#update
PUT /pro/users/:id(.:format) pro/users#update
DELETE /pro/users/:id(.:format) pro/users#destroy
pro_list_users GET /pro/acheteurs(.:format) pro/users#index
pro_this_user GET /pro/acheteur/:id(.:format) pro/users#show
pro GET /pro/users/download_pdf/:id(.:format) pro/users#download_pdf
realtor_password POST /realtors/password(.:format) realtors/passwords#create
new_realtor_password GET /realtors/password/new(.:format) realtors/passwords#new
edit_realtor_password GET /realtors/password/edit(.:format) realtors/passwords#edit
PATCH /realtors/password(.:format) realtors/passwords#update
PUT /realtors/password(.:format) realtors/passwords#update
cancel_realtor_registration GET /realtors/cancel(.:format) realtors/registrations#cancel
realtor_registration POST /realtors(.:format) realtors/registrations#create
new_realtor_registration GET /realtors/sign_up(.:format) realtors/registrations#new
edit_realtor_registration GET /realtors/edit(.:format) realtors/registrations#edit
PATCH /realtors(.:format) realtors/registrations#update
PUT /realtors(.:format) realtors/registrations#update
DELETE /realtors(.:format) realtors/registrations#destroy
realtors_credit_card_info GET /realtors/credit_card_info(.:format) realtors/registrations#credit_card_info
realtors_cancel_subscription GET /realtors/cancel_subscription(.:format) realtors/registrations#cancel_subscription
realtors_edit_profile0 GET /pro/informations-personnelles(.:format) realtors/registrations#edit_profile0
realtors_edit_profile1 GET /pro/zone-activite(.:format) realtors/registrations#edit_profile1
realtors_edit_profile GET /realtors/edit_profile(.:format) realtors/registrations#edit_profile
realtors_update_profile1 PUT /realtors/update_profile1(.:format) realtors/registrations#update_profile1
realtors_update_profile0 PUT /realtors/update_profile0(.:format) realtors/registrations#update_profile0
realtors_update_avatar PUT /realtors/update_avatar(.:format) realtors/registrations#update_avatar
realtors_update_logo PUT /realtors/update_logo(.:format) realtors/registrations#update_logo
user_password POST /users/password(.:format) users/passwords#create
new_user_password GET /users/password/new(.:format) users/passwords#new
edit_user_password GET /users/password/edit(.:format) users/passwords#edit
PATCH /users/password(.:format) users/passwords#update
PUT /users/password(.:format) users/passwords#update
cancel_user_registration GET /users/cancel(.:format) users/registrations#cancel
user_registration POST /users(.:format) users/registrations#create
new_user_registration GET /users/sign_up(.:format) users/registrations#new
edit_user_registration GET /users/edit(.:format) users/registrations#edit
PATCH /users(.:format) users/registrations#update
PUT /users(.:format) users/registrations#update
DELETE /users(.:format) users/registrations#destroy
users_pdf GET /users/pdf(.:format) users/registrations#pdf
users_download_pdf GET /users/download_pdf(.:format) users/registrations#download_pdf
users_edit_profile0 GET /informations-personnelles(.:format) users/registrations#edit_profile0
users_edit_profile1 GET /vous-et-votre-projet(.:format) users/registrations#edit_profile1
users_edit_profile2 GET /caracteristiques-du-bien(.:format) users/registrations#edit_profile2
users_edit_profile3 GET /details-du-bien(.:format) users/registrations#edit_profile3
users_edit_profile4 GET /quartier(.:format) users/registrations#edit_profile4
users_edit_profile5 GET /lieu(.:format) users/registrations#edit_profile5
users_edit_profile6 GET /budget(.:format) users/registrations#edit_profile6
users_edit_profile7 GET /coup-de-coeur(.:format) users/registrations#edit_profile7
users_update_avatar PUT /users/update_avatar(.:format) users/registrations#update_avatar
users_update_profile0 PUT /users/update_profile0(.:format) users/registrations#update_profile0
users_update_profile1 PUT /users/update_profile1(.:format) users/registrations#update_profile1
users_update_profile2 PUT /users/update_profile2(.:format) users/registrations#update_profile2
users_update_profile3 PUT /users/update_profile3(.:format) users/registrations#update_profile3
users_update_profile4 PUT /users/update_profile4(.:format) users/registrations#update_profile4
users_update_profile5 PUT /users/update_profile5(.:format) users/registrations#update_profile5
users_update_profile6 PUT /users/update_profile6(.:format) users/registrations#update_profile6
users_update_profile7 PUT /users/update_profile7(.:format) users/registrations#update_profile7
users_edit_delete GET /users/edit_delete(.:format) users/registrations#delete
heating GET /users/heating(.:format) users/registrations#heating
water_heater GET /users/water_heater(.:format) users/registrations#water_heater
有人可以帮助我吗?
答案 0 :(得分:2)
在较新版本的devise_for
中不推荐将该块传递给Devise
。这就是您在块中传递给devise_for
的路由被完全忽略的原因。您可以在rake routes
结果中注意到这一点,这些路线无处可见。
由于路线本身不存在,因此您在访问destroy_user_session_path
或new_user_session_path
时会收到错误。
要解决此问题,您需要在devise_scope
中添加这些路线:
## You need to skip `:registrations` and `:passwords` routes too because you are resetting them as well
devise_for :users,
:controllers => { :registrations => "users/registrations",
:passwords => "users/passwords",
:sessions => 'users/sessions'},
:skip => [:sessions, :registrations, :passwords]
devise_scope :user do
get 'identification' => 'users/sessions#new', :as => :new_user_session
post 'identification' => 'users/sessions#create', :as => :user_session
get 'deconnexion' => 'users/sessions#destroy', :as => :destroy_user_session
get 'inscription' => 'users/registrations#new', :as => :new_user_registration
get 'mot-de-passe' => "users/passwords#new", :as => :new_password_user
get 'mon-compte' => "users/registrations#edit", :as => :edit_user_registration
## Rest of the routes
end
查看Github Devise Issue: devise_for block deprecation warning confuses以供参考。