gpt4 book ai didi

ruby-on-rails - "devise_for"、 "devise_scope"出现问题!

转载 作者:行者123 更新时间:2023-12-03 00:49:20 26 4
gpt4 key购买 nike

我正在尝试在设计中自定义我的路线。我尝试使用 devise_scope :user,但它不起作用。所以我改为 devise_for,并跳过了自定义路由(注册、确认、密码、 session )并且它起作用了。但是,例如,当我调用“session_path”时,我的 View 中会出现错误。它正在制作一个重定向到“session.user”的表单,这是没有意义的。

这是代码:

  #routes.rb  devise_for :users, :path => '', :skip => [ :passwords, :registrations, :confirmations] do    post   "account/password",      :to => "devise/passwords#create"    get    "account/password/new",  :to => "devise/passwords#new", :as => "new_password"    get    "account/password/edit", :to => "devise/passwords#edit", :as => "edit_password"    put    "account/password",      :to => "devise/passwords#update"    post   "account",               :to => "users/registrations#create"    get    "sign_up",               :to => "users/registrations#new"    delete "account",               :to => "users/registrations#destroy"    post   "confirmation",          :to => "devise/confirmations#create"    get    "confirmation/new",      :to => "devise/confirmations#new", :as => "new_confirmation"    get    "confirmation",          :to => "devise/confirmations#show"  end

新 session View :

  #users/sessions/new.html.erb  = form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>

错误:

No route matches {:action=>"new", :format=>:user, :controller=>"devise/passwords"}

我该怎么办? “devise_scope”发生了什么无法正常工作(它显示的错误是“无法找到...的设计映射”)?

谢谢

最佳答案

正在生成哪些路由?运行 rake 路线来找出答案。

如果您没有看到所需的路由,请尝试在 devise_for 语句之后的 as block 上定义自定义路由。比如

devise_for :users, skip => [ :passwords, :registrations, :confirmations]

as :user do
post "account/password" => "devise/passwords#create"
get "account/password/new" => "devise/passwords#new"
get "account/password/edit" => "devise/passwords#edit"
put "account/password" => "devise/passwords#update"
...

end

您可能还需要自定义 View 以指向您声明的新路径。请参阅 Devise wiki 以了解如何自定义 View 。

关于ruby-on-rails - "devise_for"、 "devise_scope"出现问题!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5503485/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com