Здравствуйте, я создаю приложение ROR Survey для обследования. У меня проблема с сохранением нескольких объектов в моей базе данных. Мои параметры после отправки выглядят все хорошо, но вместо этого получают ошибку:
undefined method
allow 'для #Array: 0x00007ff29d873010`
Мои параметры выглядят как
Parameters: {
"utf8"=>"✓",
"authenticity_token"=>"vdUPSIU43ex1Wx3qZB4Xr6qNEaG0FbEyK2tkJ9OCcAtxK3jHe5lKVohS9JFOdpx/cISwIvzAKTRGw5zxUUS4QA==",
"survey_response"=>[
{"user_id"=>"1", "survey_question_id"=>"22", "answer"=>"Hello"},
{"user_id"=>"1", "survey_question_id"=>"23", "answer"=>"Hello"}],
"commit"=>"Create Survey response"
}
Мои методы survey_response_params:
def survey_response_params
params.require(:survey_response).permit(:answer, :survey_question_id, :user_id, :survey_answer_id)
end
Мой контроллер выглядит так:
class SurveyResponsesController < ApplicationController
def index
@survey_responses = SurveyResponse.all
end
def show
end
def new
@survey_response = SurveyResponse.new
@survey = Survey.find(1)
@survey_questions = @survey.survey_questions
end
def edit
@survey = Survey.find(1)
@survey_questions = @survey.survey_questions
end
def create
@survey_response = SurveyResponse.new(survey_response_params)
respond_to do |format|
if @survey_response.save
format.html { redirect_to @survey_response, notice: 'Survey response was successfully created.' }
format.json { render :show, status: :created, location: @survey_response }
else
format.html { render :new }
format.json { render json: @survey_response.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @survey_response.update(survey_response_params)
format.html { redirect_to @survey_response, notice: 'Survey response was successfully updated.' }
format.json { render :show, status: :ok, location: @survey_response }
else
format.html { render :edit }
format.json { render json: @survey_response.errors, status: :unprocessable_entity }
end
end
end
def destroy
@survey_response.destroy
respond_to do |format|
format.html { redirect_to survey_responses_url, notice: 'Survey response was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_survey_response
@survey_response = SurveyResponse.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def survey_response_params
params.permit(survey_response: [:answer, :survey_question_id, :user_id, :survey_answer_id])
end
end
Модель
class SurveyResponse < ApplicationRecord
belongs_to :survey_question
belongs_to :user
end