2

パラメータを使用:

{"utf8"=>"✓",
 "_method"=>"put",
 "authenticity_token"=>"mZ0yUwkdUhi8JVeXfPPzukYr8QfmJjC0UptG3rS08Fo=",
 "commit"=>"Update Artist",
 "artist"=>{"name"=>"Test",
 "bio"=>"Some bio",
 "city"=>"Chicago",
 "state"=>"IL",
 "visible"=>"1",
 "published_at"=>"2013-06-05 20:23:48 UTC",
 "confirmed_at"=>"2013-06-05 12:00:00 UTC",
 "galleries_attributes"=>{"0"=>{"media_items_attributes"=>{"1370495729379"=>{"_destroy"=>"0",
 "mediable_type"=>"Image",
 "mediable_id"=>"45"}}}}},
 "id"=>"test"}

アーティストモデルの attr_accessible に次のものがあります

attr_accessible :media_items_attributes, :galleries_attributes, :name, :bio, :permalink, :billboard_image_id, :featured_at, :city, :state, :country, :latitude, :longitude, :visible, :confirmed_at, :published_at, :deleted_at, :genre_ids, as: :admin

しかし、私はまだ例外が発生します

Can't mass-assign protected attributes: media_items_attributes

私のギャラリーモデルには次のものがあります

attr_accessible :media_items_attributes

私は困惑しています。

どこで許可する必要があります:media_items_attributesか?

class Gallery < ActiveRecord::Base
  belongs_to :galeryable
  attr_accessible :media_items_attributes
  has_many :media_items, :as => :mediable


  accepts_nested_attributes_for :media_items

end


class Artist < ActiveRecord::Base


# Basic attibutes, associations and validations
  # ----------------------------------------------------------------------------------------------------

  attr_accessible :media_items_attributes, :galleries_attributes, :name, :bio, :permalink, :billboard_image_id, :featured_at, :city, :state, :country, :latitude, :longitude, :visible, :confirmed_at, :published_at, :deleted_at, :genre_ids, as: :admin

  # Validations
  validates_presence_of :name, :bio, :city, :state
  validate :publishable

  # Geocode the artist based on city and state
  geocoded_by :city_state
    after_validation :geocode

  has_many :genrefications, as: :genreable, dependent: :destroy
  has_many :genres, through: :genrefications
  has_many :galleries, as: :galleryable
  accepts_nested_attributes_for :galleries

end
4

2 に答える 2

2

私の推測: ギャラリー モデルで。

ネストされたハッシュの外観から、media_items_attributes は gallery_attributes セクションの下にあります。そのため、そのレベルに置く必要があります。

于 2013-06-06T05:18:38.397 に答える