Dear Community, I''m using Ruby and especially Ruby on Rails only for a short time, so please excuse me, if the answer to my following question is obvious. Please also excuse my bad English, it''s not my mother tongue - feel free to give me hints how to improve my English :) I have a two model files called StorageSlot and Product: class StorageSlot < ActiveRecord::Base has_many :products belongs_to :building end class Building < ActiveRecord::Base belongs_to :storage_slots end Now I can access all products belonging to a slot by using slot.products. I even can add products using slot.products <<, slot.products.build, slot.products.create, and so on. Each slot has a specified number of maximal products, which is of course not recognized by these methods. How can I overwrite them to perform a check if the slot is already full ? I hope you understand my problem as I don''t have any ideas how to solve it. Thank you for your help in advance and greetings from Austria :) Christoph --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jun 11, 5:10 pm, Christoph <chrisi.dibi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > class Building < ActiveRecord::Base > belongs_to :storage_slots > endI assume you mean class Product.> > Now I can access all products belonging to a slot by using > slot.products. I even can add products using slot.products <<, > slot.products.build, slot.products.create, and so on. Each slot has a > specified number of maximal products, which is of course not > recognized by these methods. How can I overwrite them to perform a > check if the slot is already full ? >Use a before_add callback ? Fred> I hope you understand my problem as I don''t have any ideas how to > solve it. Thank you for your help in advance and greetings from > Austria :) > > Christoph--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Yes, I''m sorry, I copied the false piece of code^^ :(. On 11 Jun., 18:18, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I assume you mean class Product.Yes, I''m very sorry, I copied the false piece of code^^ :(.> Use a before_add callback ?Sorry, as I''m a newbie, could you please explain it to me. Christoph --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 11 Jun 2008, at 17:29, Christoph wrote:> > >> Use a before_add callback ? > Sorry, as I''m a newbie, could you please explain it to me.see association callbacks at http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> see association callbacks athttp://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMet...Thank you very much, this is exactly what I was looking for. I''m very glad about the quick and friendly help and - once again - about the capabilities of Rails. Christoph --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---