Abhi
Abhi

Reputation: 4261

Rails form_for pass params as Array

I have a page where I may add n number of questions. And my questions partial contains a form as follows:

= form_for :question, :url => questions_path do |f|
  = f.text_field :title

What I get in params is "question"=>{"title"=>"Some Name"}. But, if I click Add New Question button the same partial is rendered below. My problem is I still get the first questions params even if I have 2 forms now. Is there a way to get params like

"question"=>{["title"=>"Some Name"], ["title"=>"Some Other Name"]}

Upvotes: 1

Views: 4825

Answers (1)

Rahul Singh
Rahul Singh

Reputation: 3427

try this

= form_for :question, :url => questions_path do |f|
  = f.text_field :title, name: "question[title][]"

for more info refer http://guides.rubyonrails.org/action_controller_overview.html#hash-and-array-parameters

Upvotes: 4

Related Questions