Hi, I have a very sime app. I need to create as many records in the db as the selected checkboxes (named :isselected) in the view. Here is the code snippet from the controller: isselectedhash = params[:isselected] for mod in isselectedhash.keys @issue = Issue.new(params[:issue]) @issue.state = ''NEW'' @issue.mod_id = isselectedhash[mod] # this gets the mod_id logger.warn("saving ....") logger.warn(@issue) @issue.save end When I have two boxes selected this loop goes thru twice, but only one record is created in the DB. Here is the log,. Note, no SQL for the second object that needs to be saved. Why is that? ---------------------------------------------------------------------------------------------------------------------------------------------------- Processing IssuesController#create Parameters: {"commit"=>"Create", "action"=>"create", "controller"=>"issues", "issue"=>{"project_id"=>"1", "description"=>"desc", "solution"=>"desc", "owner"=>"qqqq"}, "isselected"=>{"KSS2"=>"2", "KSS"=>"1"}} saving .... #<Issue:0x690a58c> [4;35;1mSQL (0.000000) [0m [0mBEGIN [0m [4;36;1mSQL (0.000000) [0m [0;1mINSERT INTO issues (`project_id`, `mod_id`, `number`, `date`, `description`, `solution`, `owner`, `state`) VALUES(1, 2, ''1013'', ''2007-05-04 07:49:46'', ''desc'', ''desc'', ''qqqq'', ''NEW'') [0m [4;35;1mSQL (0.031000) [0m [0mCOMMIT [0m added new issue KSS 1 saving .... #<Issue:0x6902a1c> added new issue Redirected to http://localhost:3000/issues/list ---------------------------------------------------------------------------------------------------------------------------------------------------- Can anyone please help? Thanks, Anupam. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> When I have two boxes selected this loop goes thru twice, but only > one record is created in the DB. > Here is the log,. Note, no SQL for the second object that needs to > be saved. Why is that?If a record doesn''t save, it means a validation failed, or a before_* callback cancelled it. http://rails.rubyonrails.org/classes/ActiveRecord/Validations.html http://rails.rubyonrails.org/classes/ActiveRecord/Callbacks.html -- Rick Olson http://lighthouseapp.com http://weblog.techno-weenie.net http://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
What you could do is add an exclamation mark to your .save call which would make it bark if the save isn''t getting executed for some reason. So instead of just @issue.save, it would be @issue.save! That may point you in a certain direction, maybe that record isn''t valid for some reason. Curtis http://www.okwithfailure.com On May 4, 5:03 am, anupam <anupambak...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > I have a very sime app. > I need to create as many records in the db as the selected > checkboxes (named :isselected) in the view. > > Here is the code snippet from the controller: > > isselectedhash = params[:isselected] > for mod in isselectedhash.keys > @issue = Issue.new(params[:issue]) > > @issue.state = ''NEW'' > @issue.mod_id = isselectedhash[mod] # this gets the mod_id > > logger.warn("saving ....") > logger.warn(@issue) > @issue.save > end > > When I have two boxes selected this loop goes thru twice, but only > one record is created in the DB. > Here is the log,. Note, no SQL for the second object that needs to > be saved. Why is that? > > ---------------------------------------------------------------------------------------------------------------------------------------------------- > Processing IssuesController#create > Parameters: {"commit"=>"Create", "action"=>"create", > "controller"=>"issues", "issue"=>{"project_id"=>"1", > "description"=>"desc", "solution"=>"desc", "owner"=>"qqqq"}, > "isselected"=>{"KSS2"=>"2", "KSS"=>"1"}} > saving .... > #<Issue:0x690a58c> > [4;35;1mSQL (0.000000) [0m [0mBEGIN [0m > [4;36;1mSQL (0.000000) [0m [0;1mINSERT INTO issues > (`project_id`, `mod_id`, `number`, `date`, `description`, `solution`, > `owner`, `state`) VALUES(1, 2, ''1013'', ''2007-05-04 07:49:46'', ''desc'', > ''desc'', ''qqqq'', ''NEW'') [0m > [4;35;1mSQL (0.031000) [0m [0mCOMMIT [0m > added new issue > KSS > 1 > saving .... > #<Issue:0x6902a1c> > added new issue > Redirected tohttp://localhost:3000/issues/list > ---------------------------------------------------------------------------------------------------------------------------------------------------- > > Can anyone please help? > > Thanks, > Anupam.--~--~---------~--~----~------------~-------~--~----~ 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, Thanks for the pointers. I haven''t overriden any of the default methods of the ActiveRecord::Base class. I even tried to define them (validate*) methods. Yet, I get the same result, only one record is created. Any way to turn on debugging to see the entire stack trace? Thanks, Anupam On May 4, 9:58 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > When I have two boxes selected this loop goes thru twice, but only > > one record is created in the DB. > > Here is the log,. Note, no SQL for the second object that needs to > > be saved. Why is that? > > If a record doesn''t save, it means a validation failed, or a before_* > callback cancelled it. > > http://rails.rubyonrails.org/classes/ActiveRecord/Validations.htmlhttp://rails.rubyonrails.org/classes/ActiveRecord/Callbacks.html > > -- > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephistoblog.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 -~----------~----~----~----~------~----~------~--~---
I found the error. It was a logical error in my code! In order to get the error condition I had: dberror ||= issue.save (once I got a true from the first iteration, it never did the second save onwards) I changed it to following and it works: dberror &&= issue.save I would still like to know if there is a way to run rails in a debug mode to see the stack trace. Thanks, Anupam. On May 5, 8:50 pm, anupam <anupambak...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > Thanks for the pointers. > I haven''t overriden any of the default methods of the > ActiveRecord::Base class. I even tried to define them (validate*) > methods. > Yet, I get the same result, only one record is created. > > Any way to turn on debugging to see the entire stack trace? > > Thanks, > Anupam > > On May 4, 9:58 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > When I have two boxes selected this loop goes thru twice, but only > > > one record is created in the DB. > > > Here is the log,. Note, no SQL for the second object that needs to > > > be saved. Why is that? > > > If a record doesn''t save, it means a validation failed, or a before_* > > callback cancelled it. > > >http://rails.rubyonrails.org/classes/ActiveRecord/Validations.htmlhtt... > > > -- > > Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
anupam wrote:> I found the error. It was a logical error in my code! In order to get > the error condition I had: > dberror ||= issue.save > (once I got a true from the first iteration, it never did the second > save onwards) > > I changed it to following and it works: > dberror &&= issue.saveThe save method just returns true or false, so I''m not sure what you''re gaining with this. The usual approach is to say: if issue.save #do something else #... end> I would still like to know if there is a way to run rails in a debug > mode to see the stack trace.Rails has the concept of "run modes": development, production and test. While you are developing, you run in development mode (that''s the default, so it''s probably what you are doing). Rails logs to a log file with the name of the mode in the log directory. So, if you tail development.log, you should see any stack traces, queries, etc. Also, if an exception is thrown while running in development mode, rails should give you an error page in the browser with the stack trace. b> Thanks, > Anupam. > > > On May 5, 8:50 pm, anupam <anupambak...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Hi, >> Thanks for the pointers. >> I haven''t overriden any of the default methods of the >> ActiveRecord::Base class. I even tried to define them (validate*) >> methods. >> Yet, I get the same result, only one record is created. >> >> Any way to turn on debugging to see the entire stack trace? >> >> Thanks, >> Anupam >> >> On May 4, 9:58 am, "Rick Olson" <technowee...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> >> >> >>>> When I have two boxes selected this loop goes thru twice, but only >>>> one record is created in the DB. >>>> Here is the log,. Note, no SQL for the second object that needs to >>>> be saved. Why is that? >>> If a record doesn''t save, it means a validation failed, or a before_* >>> callback cancelled it. >>> http://rails.rubyonrails.org/classes/ActiveRecord/Validations.htmlhtt... >>> -- >>> Rick Olsonhttp://lighthouseapp.comhttp://weblog.techno-weenie.nethttp://mephist...- Hide quoted text - >> - Show quoted text - > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---