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 Cheung 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
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.