【问题标题】:Rails form_for with route namespace and as attribute带有路由命名空间和属性的 Rails form_for
【发布时间】:2018-09-23 15:00:13
【问题描述】:

我在 Rails 5 中使用 form_for 助手,使用路由命名空间功能并作为模型名称的别名。

我的路线:

      edit_customer_profile GET    /customer/profile/edit(.:format)                                           customer/profiles#edit
           customer_profile PATCH  /customer/profile(.:format)                                                customer/profiles#update
                            PUT    /customer/profile(.:format)                                                customer/profiles#update

我的看法:

... omit verbosity ...
<%= form_for [:customer, current_user], as: :profile do |f| %>
... omit verbosity ...

我的错误:

undefined method `customer_user_path' for #<#<Class:0x007f0f8d0ddce0>:0x00558c965b4a78>

手头有文档,表单助手必须使用customer_profile_path 而不是customer_user_path

【问题讨论】:

  • &lt;%= form_for [:customer, (current_user, as: :profile)] do |f| %&gt; 不确定这是否有效。
  • 不,不工作

标签: ruby-on-rails forms routes helpers


【解决方案1】:

使用form_with[:customer, current_user], as: :profile do

【讨论】:

  • 不,返回错误wrong number of arguments (given 1, expected 0)
猜你喜欢
  • 1970-01-01
  • 2018-03-15
  • 2011-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-02
  • 1970-01-01
  • 2011-02-23
相关资源
最近更新 更多