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 -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2010-Mar-08 21:26 UTC
Re: ActiveRecord::ReadOnlyRecord on attributes_update
On Mar 8, 8:09 pm, Greg Ma <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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> Someone had this error? > > Best, > greg > -- > Posted viahttp://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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
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
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.