Mithun Sreedharan
Mithun Sreedharan

Reputation: 51292

Ruby on Rails - Getting parameter values as hash onside controller

How can i get 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}

Upvotes: 1

Views: 667

Answers (1)

shingara
shingara

Reputation: 46914

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

Upvotes: 2

Related Questions