【问题标题】:Devise routing, problems customising Devise routes设计路线,自定义设计路线的问题
【发布时间】:2013-10-10 18:36:24
【问题描述】:

自定义设计路线后,我遇到了一些路线问题。

当前设置(但失败):

  • /me/account 加载 Devise::Registration#edit form
  • /me/account/:什么路由到 account_controller#edit

我的路线(捷径):

  devise_for :users do
   ...
  end

  devise_scope :user do
    scope "/me/account" do
      get "/" => "users/registrations#edit", :as => :my_account
      get "/:what" => "accounts#edit", :as => :my_account_edit    
    end
  end

  resources :accounts, :only => [:edit, :update]

Rake 路由输出:

           activate_account GET    /reactivate(.:format)                             users#reactivate
                 my_account GET    /me/account(.:format)                             users/registrations#edit
            my_account_edit GET    /me/account/:what(.:format)                       accounts#edit
                     cancel GET    /me/account/cancel(.:format)                      users/registrations#cancel
                            DELETE /me/account(.:format)                             users/registrations#destroy
               edit_account GET    /accounts/:id/edit(.:format)                      accounts#edit
                    account PATCH  /accounts/:id(.:format)                           accounts#update
                            PUT    /accounts/:id(.:format)                           accounts#update

帐户

由于 /me/account 实际上显示注册#edit ( Devise ) 并且所有 /me/account/helpme 都是自定义表单字段

这有问题:

  • /me/account 上没有显示更新或失败的通知
  • 如果失败,则不会使用之前填写的表单值重新填充表单
  • 它没有更新表单
  • /me/account/helpme 在表单提交时转到 /accounts/1(当前用户 ID)并抛出错误

    没有路由匹配 {:action=>"edit", :controller=>"accounts", :id=>"1", :what=>nil} 缺少必需的键:[:what]

这些问题完全把我逼疯了。谁能给我一些建议来解决(一个或多个)这些路由问题?

【问题讨论】:

  • 对不起,这只是超级混乱。我不知道从哪里开始回答你的问题。

标签: ruby-on-rails-3 devise routes ruby-on-rails-4


【解决方案1】:

关于表单提交错误。

您需要覆盖表单中的 url 以提交到:

<%= form_for @resource, url: my_account_edit(what: params[:what]) do |f| %>

这应该在您的视图或设计生成的视图中完成。

如果您没有生成设计视图,那么,只需在终端中运行:

rails g devise:views

编辑

您应该告诉我们您的表单在视图中的外观,以及控制器如何处理自定义字段的更新。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多