使用rails 4強參數時出錯。未找到參數:在rails4強參數中
ActionController::ParameterMissing at /questions
param not found: question
我有一個Question model
和questions controller
。這些問題表有content column
這是包含在questions controller
class QuestionsController < ApplicationController
def index
@question = Question.new(question_params)
@questioner = Questioner.new(questioner_params)
end
def new
@question = Question.new(question_params)
end
def edit
@question = find(params[:id])
raise "Question Not edited!" unless @question
end
def create
@question = Question.new(question_params)
respond_to do |wants|
if @question.save
flash[:notice] = 'You have successfully posted the questions!'
wants.html { redirect_to(root_path) }
wants.xml { render :xml => @question, :status => :created, :location => @question }
else
flash[:error] = "Please review the problems below."
wants.html { redirect_to(questions_path) }
wants.xml { render :xml => @question.errors, :status => :unprocessable_entity }
end
end
end
private
def question_params
params.require(:question).permit(:content)
end
end
我在索引頁中有一個2表單。一個使用問題和另一個提問者 – ben