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
精彩评论