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.