Hello, I have two models that look like the following: ModelA: attr_accessible :date, ... has_many :modelb accepts_nested_attributes_for :modelb end ModelB: attr_accessible :date, ... belongs_to :modela, :modelc, :modeld end And then in ModelAs controller: @modela = Modela.new 3.times do |i| @modela.modelb.build(:date => Time.now) end When ModelB has 3 belongs_to and I attempt to build the association with just ModelA I get the following error: ArgumentError wrong number of arguments (3 for 2) When ModelB just belongs_to modela it works. Do I need to somehow setup a fake association for the other belong_tos? Those are to be created in the UI by the user. Thanks, Jarod -- 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 To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/Gv5tkWCmhlQJ. For more options, visit https://groups.google.com/groups/opt_out.
On 12 December 2012 15:18, Jarod Watkins <jwatkins-BlZJrTnzxPPQT0dZR+AlfA@public.gmane.org> wrote:> Hello, > I have two models that look like the following: > > ModelA: > attr_accessible :date, ... > has_many :modelbThat should be modelbs, plural.> accepts_nested_attributes_for :modelb > end > > ModelB: > attr_accessible :date, ... > belongs_to :modela, :modelc, :modeldI think you have to specify those on separate lines. Colin> end > > And then in ModelAs controller: > > @modela = Modela.new > > 3.times do |i| > @modela.modelb.build(:date => Time.now) > end > > When ModelB has 3 belongs_to and I attempt to build the association with > just ModelA I get the following error: > > ArgumentError wrong number of arguments (3 for 2) > > When ModelB just belongs_to modela it works. Do I need to somehow setup a > fake association for the other belong_tos? Those are to be created in the UI > by the user. > > Thanks, > Jarod > > -- > 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 > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-talk/-/Gv5tkWCmhlQJ. > For more options, visit https://groups.google.com/groups/opt_out. > >-- 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 https://groups.google.com/groups/opt_out.
Ah thanks Colin, that was it! On Wed, Dec 12, 2012 at 10:28 AM, Colin Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 12 December 2012 15:18, Jarod Watkins <jwatkins-BlZJrTnzxPPQT0dZR+AlfA@public.gmane.org> wrote: > > Hello, > > I have two models that look like the following: > > > > ModelA: > > attr_accessible :date, ... > > has_many :modelb > > That should be modelbs, plural. > > > accepts_nested_attributes_for :modelb > > end > > > > ModelB: > > attr_accessible :date, ... > > belongs_to :modela, :modelc, :modeld > > I think you have to specify those on separate lines. > > Colin > > > end > > > > And then in ModelAs controller: > > > > @modela = Modela.new > > > > 3.times do |i| > > @modela.modelb.build(:date => Time.now) > > end > > > > When ModelB has 3 belongs_to and I attempt to build the association with > > just ModelA I get the following error: > > > > ArgumentError wrong number of arguments (3 for 2) > > > > When ModelB just belongs_to modela it works. Do I need to somehow setup a > > fake association for the other belong_tos? Those are to be created in > the UI > > by the user. > > > > Thanks, > > Jarod > > > > -- > > 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 > > To view this discussion on the web visit > > https://groups.google.com/d/msg/rubyonrails-talk/-/Gv5tkWCmhlQJ. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > -- > 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 https://groups.google.com/groups/opt_out. > > >-- 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 https://groups.google.com/groups/opt_out.