0
我踐行着CRUD TDD和我遇到了此問題:未定義的局部變量或方法`question_params',儘管它被定義
undefined local variable or method `question_params' for #<QuestionsController:0x0000010618a248>
這裏是我的規格(雖然我認爲他們是不相關的):
describe '#create' do
it 'assigns @question to a new question' do
post :create
expect(assigns(:question)).to be_a_new(Question)
end
it 'redirects to the question once created' do
post :create
expect(response).to redirect_to question_path(@question)
end
end
這裏是控制器:
class QuestionsController < ApplicationController
def new
@question = Question.new
end
def show
@question = Question.find(params[:id])
end
def create
@question = Question.new(question_params)
if @question.save
redirect_to @question
else
render :new
end
private
def question_params
params.require(:question).permit(:title, :body)
end
end
end
這是怎麼回事?
哦,天哪。 ** **捂臉 – 2014-08-28 02:50:43