次のエラーがあります
undefined method `[]' for nil:NilClass
app/controllers/events_controller.rb:60:in `create'
この場合、nilが何を意味するのかわかりません。ここで私のコントローラーと60行目は矢印がどこにあるかです
def create
@event = current_customer.events.build(params[:event])
@location = @event.locations.build(params[:location])
--->@location.longitude = params[:location][:longitude]
@location.latitude = params[:location][:latitude]
respond_to do |format|
if @location.save
if @event.save
format.html { redirect_to @event, notice: 'Event was successfully created.' }
format.json { render json: @event, status: :created, location: @event }
else
format.html { render action: "new" }
format.json { render json: @event.errors, status: :unprocessable_entity }
end
end
end
end
イベントと場所の2つのモデルがあり、2つのイベントを同時に作成しており、イベントには多くの場所があります。経度はattr_accesorの経度と緯度です。隠しフィールドタイプ。