代码之家  ›  专栏  ›  技术社区  ›  Rubytastic

偏离路线,定制偏离路线的问题

  •  -2
  • Rubytastic  · 技术社区  · 12 年前

    在定制了Devise路线后,我在路线上遇到了一些问题。

    当前设置(但失败):

    • /我/帐户加载Devise::注册#编辑表单
    • /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/帐户上没有显示任何通知
    • 失败时,表单不会重新填充以前填写的表单值
    • 它没有更新表单
    • /me/account/helpme在表单提交时转到/account/1(当前用户id)并抛出错误

      没有路由匹配{:action=>“edit”,:controller=>,“accounts”,:id=>

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

    1 回复  |  直到 12 年前
        1
  •  1
  •   Waterlink    12 年前

    关于表单提交错误。

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

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

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

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

    rails g devise:views
    

    编辑

    您应该告诉我们视图中的窗体是什么样子的,以及控制器如何处理自定义字段的更新。