嵌套模型表单错误

时间:2010-11-07 19:00:09

标签: ruby-on-rails ruby model nested-forms

我有一个嵌套的模型表单,它会为#< Array:0x1060460d0>抛出错误“undefined method'media_type'”调用update_attributes时。 media_type关联有什么问题?

class Publication < ActiveRecord::Base
  has_many :products
  accepts_nested_attributes_for :products, :allow_destroy => true
end

class Product < Offering
  belongs_to :media_type
end

class Offering < ActiveRecord::Base
  belongs_to :publication
end

class MediaType < ActiveRecord::Base
  belongs_to :meaning
  has_many :products
end

以下是我提交给表单的内容。

{"commit"=>"Commit changes",
 "_method"=>"put",
 "authenticity_token"=>"e2/62ffmRVuNsCVP65zy4SLprWgRSa+DdLc2RXzM+UQ=",
 "id"=>"628",
 "publisher_publication"=>{"edition_attributes"=>{"title"=>"this is the title",
 "short_description"=>"this is the description",
 "abstract"=>"",
 "subtitle"=>"",
 "id"=>"200",
 "long_description"=>"",
 "title_prefix"=>"",
 "work_attributes"=>{"id"=>"200"}},
 "volume"=>"",
 "issue"=>"",
 "date_published"=>"2006-09-20",
 "products_attributes"=>{"1289147822429"=>{"price"=>0,
 "document"=>#<File:/var/folders/e9/e965IrazFgu0fm-rjRtvIk+++TI/-Tmp-/RackMultipart20101107-638-1vffwzk-0>,
 "media_type_id"=>"1"}},
 "imprint_id"=>"3"}}

这是我的控制器动作。

def update
  @publication = Publisher::Publication.find(params[:id])

  if @publication.update_attributes(params[:publisher_publication])
    flash[:notice] = "Successfully updated publication and products."
    redirect_to(publisher_publication_url(@publication))
  else
    render :action => 'edit'
  end
end

1 个答案:

答案 0 :(得分:0)

我刚刚使用rails console ...

对问题进行了排查,解决了similar problem问题

也许这对你也有帮助。

相关问题