Hi, I have a form, that after submit saves data in 2 different tables.
It works fine, only in the member-table there is an extra record added,
each time the user submits data, with in the rubric_idfield NULL. I
checked the parsed data, and they are fine, no extra anything. Should
be simple but I cannot pinpoint it. Please, if you could spare some
time...
Code:
Action Combination.transaction do
@members.combination = @combination
@combination.add_rubrics(@rubrics)
@combination.save
@members.save
end
add_rubrics
def add_rubrics(rubrics)
rubrics.items.each do |item|
li = Member.new_rubric(item)
members << li
end
end
new_rubric(item)
def self.new_rubric(item)
li = self.new
li.rubric_id = item.id
li
end
I''m convinced it has to be here, but I don''t know why it
happens.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Could it be that at the point at which this code runs one of the @rubrics has an item that has not been saved yet (and thus doesn not have an id) ? 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-/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 -~----------~----~----~----~------~----~------~--~---
Hi Fred, thanks for replying. Unjfortunately, I don''t think that is the case. The rubrics all come from a predefined list, so there is no saving involved before @rubrics is created. That is what makes is so wierd for me. Frederick Cheung schreef:> Could it be that at the point at which this code runs one of the > @rubrics has an item that has not been saved yet (and thus doesn not > have an id) ? > > 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-/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 -~----------~----~----~----~------~----~------~--~---
Have you checked by examining all of those objects in the debugger? 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-/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 -~----------~----~----~----~------~----~------~--~---
Yep. Iknow there must be a season for this extra record, and it''s the first I''ve ever seen this. I even restarted my working sytem a few times (Mac OSX 4.8; MAMP, Locomotive, Textmate), with no difference. That''s why I''m so... flabbergasted. (Like that word) Frederick Cheung schreef:> Have you checked by examining all of those objects in the debugger? > > 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-/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 -~----------~----~----~----~------~----~------~--~---