开发者

Ruby on Rails - Getting parameter values as hash onside controller

开发者 https://www.devze.com 2023-01-31 09:05 出处:网络
How can i ge开发者_JAVA百科t the values passed in the URL check/1?Answers[1]=2&Answers[7]=3&Answers[6]=4&Answers[4]=0 in controller

How can i ge开发者_JAVA百科t the values passed in the URL check/1?Answers[1]=2&Answers[7]=3&Answers[6]=4&Answers[4]=0 in controller

@answers = params[:Answers] ?

How can i convert @answers to the format {1 => 2, 7 => 3, 6 => 4, 4 => 0}


You get that in all String you can convert is in Integer

answers  = params[:Answer].inject({}) do |answers, line|
  answers[line[0].to_i] = line[1].to_i
  answers
end
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号