Frage

take a look into my model and my migration

i only have one attribute to test the globalize3 gem

class Car < ActiveRecord::Base
   attr_accessible :name
   translates :name
end

my migration looks like the following

class CreateCars < ActiveRecord::Migration
  def up
    create_table :cars do |t|
      t.timestamps
    end
    Car.create_translation_table! :name => :string
  end

  def down
    Car.drop_translation_table!
    drop_table :cars
  end
end

and i got the following error while trying to save new car details with the attribute name

ActiveModel::MassAssignmentSecurity::Error: Can't mass-assign protected attributes: locale

i think i am missing some declaration/configuration for globalize3 to access the I18n.locale variable.

btw i am using rails 3.2.3 and ruby 1.9.3p125

War es hilfreich?

Lösung

just found an workaround to my problem by following this Issue

class Car < ActiveRecord::Base
  attr_accessible :name
  translates :name
  class Translation
    attr_accessible :locale
  end
end

Andere Tipps

Shouldn't this be like:

class Car < ActiveRecord::Base
  attr_accessible :name, :translations_attributes
  translates :name
end

See:

Rails 3.2.3: How to mass assign associated models?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top