Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 嵌套属性未保存在Rails 3.1中_Ruby_Ruby On Rails 3_Nested Attributes - Fatal编程技术网

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