-2

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

当前设置(但失败):

  • /me/account 加载 Devise::Registration#edit 表单
  • /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]

耙路线输出:

           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]

这些问题完全把我逼疯了。任何人都可以向我提供一些建议来解决(一个或多个)这些路由问题吗?

4

1 回答 1

1

关于表单提交错误。

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

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

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

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

rails g devise:views

编辑

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

于 2013-10-20T11:56:38.663 回答