开发者

Ruby on Rails - Getting parameter values as hash onside 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜