【问题标题】:Unknown attribute when saving a nested form保存嵌套表单时的未知属性
【发布时间】:2013-03-29 08:38:58
【问题描述】:

我正在用 Rails 3 编写一个引擎。我有一个 generic_recipe,其中包含这样的食谱:

module EdibleRecipe
  class GenericRecipe < ActiveRecord::Base
    attr_accessible :recipe, :recipe_attributes, ....
    has_many :recipes
    accepts_nested_attributes_for :recipes 
  end
end

表单正确呈现:

<%= f.fields_for :recipe do |r| %>
...

但是保存时,我得到:

ActiveRecord::UnknownAttributeError in EdibleRecipe::GenericRecipesController#create

Full code is here。非常感谢任何帮助:)

【问题讨论】:

  • 另一个问题是我的表单中有 f.fields_for :recipe 而不是 f.fields_for :recipes。

标签: ruby-on-rails forms attributes nested


【解决方案1】:

使用

attr_accessible :recipes_attributes

而不是 :recipe_attributes

【讨论】:

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