Ruby 嵌套属性未保存在Rails 3.1中
我有如下嵌套模型Ruby 嵌套属性未保存在Rails 3.1中,ruby,ruby-on-rails-3,nested-attributes,Ruby,Ruby On Rails 3,Nested Attributes,我有如下嵌套模型 项目模型有许多关键字,关键字属于项目 class Project < ActiveRecord::Base has_many :url_list has_many :keyword accepts_nested_attributes_for :keyword, :allow_destroy => true end class Keyword < ActiveRecord::Base belongs_to :project
项目
模型有许多关键字,关键字属于
项目
class Project < ActiveRecord::Base
has_many :url_list
has_many :keyword
accepts_nested_attributes_for :keyword, :allow_destroy => true
end
class Keyword < ActiveRecord::Base
belongs_to :project
attr_accessible :kw, :project_id
end
在项目模型中尝试以下操作:
has_many :keywords
accepts_nested_attributes_for :keywords, :allow_destroy => true
关键词-因为你有很多关联
如果不起作用,请检查log/development.log中的参数-您应该有这样的内容:“关键字属性”=>{“标题”=>“…”}
查看此页面:感谢您的回复。这很有帮助!
class CreateKeywords < ActiveRecord::Migration
def change
create_table :keywords do |t|
t.string :kw
t.integer :project_id
t.timestamps
end
end
end
has_many :keywords
accepts_nested_attributes_for :keywords, :allow_destroy => true