Create with multiple params issue

Viewed 680

I have a controller that looks like this:

def new
   @columns = Column.where(:table_id => @table.id)
   @row = Row.new(id: @table.id)
end

def create

   row_params.each do |row_param|
      @row = Row.new(row_param)
      @row.column_id = params["column_id"]

      if @row.save
         redirect_to collection_rows_path, notice: 'item was successfully created.' 
      else
         render action: 'new'
      end
   end
end

I have a form that looks like:

<%= form_for [@table, @row] do |f| %>

   <% @columns.each do |column| %>
       <%= column.id %>
       <%= hidden_field_tag :column_id, column.id %>
       <%= f.label :data %><br>
       <%= f.text_field :data %>
   <% end %>

   <%= f.submit %>
<% end %>

Basically, I'm trying to send multiple params and have them inserted with the column. But I keep getting this error:

undefined methodstringify_keys' for ["data", "No"]:Array` when there is two columns which means there is two text fields and I insert "Hello" in the first one, and "No" in the second.

Two things: Why is it only reading the "No" on the second one instead of both the "Hello" and "No"? And also why am I getting this error?

Thanks for all help!

2 Answers
Related