ActiveRecord::ReadOnlyRecord on attributes_update

Hi,

I have a ActiveRecord::ReadOnlyRecord error when i update child
attributes whereas when i create a new one it works fine.

Someone had this error?

Best,
greg

On Mar 8, 8:09 pm, Greg Ma [email protected] wrote:

Hi,

I have a ActiveRecord::ReadOnlyRecord error when i update child
attributes whereas when i create a new one it works fine.

find marks records as read only if you specify a :joins option (you
can override this with :readonly => false)

Fred

Sorry but i’m not sure where do I have to put a join.

here is my code:
class Product < ActiveRecord::Base
attr_accessible :name, :prod_type, :min_visit, :max_visit, :price,
:visible, :ingredient_attributes

has_and_belongs_to_many :ingredients
belongs_to :city_preferences :city_preferences

after_update :save_ingredients

def ingredient_attributes=(ingredient_attributes)
ingredient_attributes.each do |ingredient|
if ingredient[:id].blank?
ingredients.build(ingredient)
else
ing = Ingredient.detect {|i| i.id == ingredient[:id].to_i}
ing.attributes = ingredient
end
end
end

def save_ingredients
ingredients.each do |t|
t.save(false) #false parameter = avoid validation
end
end

end

class Ingredient < ActiveRecord::Base
attr_accessible :name, :price, :visible

has_and_belongs_to_many :products
end

Thx Greg

Frederick C. wrote:

On Mar 8, 8:09�pm, Greg Ma [email protected] wrote:

Hi,

I have a ActiveRecord::ReadOnlyRecord error when i update child
attributes whereas when i create a new one it works fine.

find marks records as read only if you specify a :joins option (you
can override this with :readonly => false)

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs