Hello everybody, I hope you can help me in this problem. I need to add an array to params in order to send some data from the view to the controller. I''m using JavaScript to dynamically add lines lihe this: <li> <input type="text" value="..."> <input type="text" value="..."> <input type="checkbox" checked="checked" value="..."> </li> Then, after the submit I need to access to the the values in this way: params[:items].each do |i| logger.debug("--> #{i[:desc]} "); logger.debug("--> #{i[:value]} "); logger.debug("--> #{i[:flag]} "); end So, I think the proper way is to add te "name" field in this way: <input type="text" name="items[0][desc]"nvalue="..."> But there is something wrong. Does someone can help me? -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Friday, October 21, 2011 3:53:33 AM UTC-4, Ruby-Forum.com User wrote:> > But there is something wrong. > Does someone can help me? >Probably. What is wrong? Are you getting any error messages? Have you checked out what params looks like in your controller (puts params.inspect)? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/8lQH4HonTw0J. 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 21 October 2011 14:22, Tim Shaffer <timshaffer-BUHhN+a2lJ4@public.gmane.org> wrote:> On Friday, October 21, 2011 3:53:33 AM UTC-4, Ruby-Forum.com User wrote: >> >> But there is something wrong. >> Does someone can help me? > > Probably. What is wrong? Are you getting any error messages? Have you > checked out what params looks like in your controller (puts params.inspect)?Also check out the html itself to make sure it looks as you expect (View > Page Source or similar in your browser) and look in the Rails log (log/development.log) to see what params are actually passed. Colin -- 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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The problem is that i get all the values in a sibngle field of the array. This is the log of the parameters: Parameters: {"items"=>{"0"=>{"flag"=>"true", "desc"=>"Description", "value"=>"2"}}, "commit"=>"Create ... If I try to get the parameters inside the items in this way: params[:items].each do |i| logger.debug("--> #{i[:desc]} "); <- row 80 logger.debug("--> #{i[:value]} "); logger.debug("--> #{i[:flag]} "); end I get this error TypeError (Symbol as array index): app/controllers/pay_checks_controller.rb:80:in `[]'' app/controllers/pay_checks_controller.rb:80:in `create'' app/controllers/pay_checks_controller.rb:79:in `each'' app/controllers/pay_checks_controller.rb:79:in `create'' But... I can acces with a direct indexing as: items[0] I get "0" and items[1] I get flagtruedescDescriptionvalue2 -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I found a solution, I have to iterate params[:items] in this way: params[:items].each do |key, value| logger.debug("--> #{value[:desc]} "); end Thanks to all. -- 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-/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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.