私はビューを持っています:
<%= form_tag mined_materials_url do %>
<%= render 'import_fields' %><br />
<%= render 'import_fields' %>
<%= button_tag :submit %>
<% end %>
_import_fields.html.erb:
<%= text_field_tag 'mined_material[][character_id]','' %>
<%= text_field_tag 'mined_material[][material_id]','' %>
<%= text_field_tag 'mined_material[][quantity]','' %>
<%= text_field_tag 'mined_material[][price]','' %>
(JS経由でフィールドを追加します)
一度に複数のレコードを同じモデルに挿入する必要がありますが、エラーのために保存に失敗します: undefined method `permit' for Array:0x00000001f63230
パラメータ:
{"utf8"=>"✓",
"authenticity_token"=>"fFR3nWwz2Q0ivED6XXyj4ICRBtj5Rdois4N++cNnCko=",
"mined_material"=>[{"character_id"=>"1",
"material_id"=>"1",
"quantity"=>"1",
"price"=>"1"},
{"character_id"=>"2",
"material_id"=>"2",
"quantity"=>"2",
"price"=>"2"}],
"button"=>""}
一括作成を許可するにはどうすればよいですか?
編集: MinedMaterialsController
class MinedMaterialsController < ApplicationController
before_action :set_mined_material, only: [:show, :edit, :update, :destroy]
before_action :load_mined_material, only: :create
load_and_authorize_resource
# GET /mined_materials/new
def new
@mined_material = MinedMaterial.new
end
# POST /mined_materials
def create
@mined_material = MinedMaterial.new(mined_material_params)
respond_to do |format|
if @mined_material.save
format.html { redirect_to new_mined_material_path, notice: 'Mined material was successfully created.' }
else
format.html { render action: 'new' }
end
end
end
def import
end
private
# Use callbacks to share common setup or constraints between actions.
def set_mined_material
@mined_material = MinedMaterial.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def mined_material_params
params.require(:mined_material).permit(:character_id, :material_id, :quantity, :price, :paid_out, :date, :corp_tax)
end
def load_mined_material
@mined_material = MinedMaterial.new(mined_material_params)
end
end