jquery - Rails form params issue -


I $ jQuery I am creating some data to send to the post, the data I send looks like this:

  authenticity_token: LxHlgi1WU8o0DtaNuiQOit / E + HlGR2plVcToHUAhA6I = employees [0] [boat_id]: 2 employees [0] [crew] []: 10 end_time: +1280408400 start_time: +1280404800  

Which jQuery is created by which by changing the data object

  • For an array found in every 'crew' Dome, make the staff called,
  • Then I can create a circle, more than the employees in the dom And its name id
  • is a list of its employees, which is then added to the crew item and is pushed on to create another array called 'Employees' array (JS is a little late, if necessary, can post

Then I have in my controller:

  def make @outing = outgoing .create (: club => current_user.club, : Title = & gt; 'Tour' ,: start_time = & gt; Time.at (parameter [: START_TIME] .to_i),: end_time => Time.at (parameter [: end_time] .to_i) @ Outgoing .save Rails.logger.debug (params [: crews] .inspect) Ultimate [: cameras] .each_with_index do | Crew, i Rails.logger.debug (crew.inspect) @crew = Crew.Create (: name_id = & gt; crew [[boat_id] .to_i,: outing_id = & gt; @outing.id) @cruce Sau crew [: crew]. Do each. C | @ Ku = crushers.scent (: cru_id = & gt; @cru.id ,: user_id = & gt; c.to_i) and end render: nothing => Right end  

Inspect two statements printed in this way:

  {"0" => {"Crew" => ["10"], "boat_id" = & gt; "2"}} ["0", {"crew" = & gt; ["10"], "boat_id" = & gt; "2"}] and I get this error:  
  TypeError (symbol as array index):  

For me, employees should not have an indexed array, and this is the issue where the issue is but I can be completely wrong. Any ideas about what is wrong or how to fix it?

Your parameters [: Crews] a hash , But you are trying to use it as if it's a array Hashes is not indexed, per copy, but rather keys.

If you (or if you do not need a key) every_v_andex :

  consultation [crews] .each_pair do | I, crew | # Note that the block parameters have been reversed ... to display the end  

:

  hash = {"0" = & Gt; {"Crew" = & gt; ["10"], "boat_id" => "2"}} hash.each_pair do | I, crew | Puts crew.inspect end # = & gt; {"Crew" = & gt; ["10"], "boat_id" = & gt; "2"}  

Note that you will still see a crew for a problem [Boat_id] , because your keys are string and not symbols Are there.


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -