後得到了堅持:'未定義的方法' 和Rails和RSpec
' undefined method `post' for #<Class:0x000001058c0f68> (NoMethodError)'
在檢查控制create
行動。
我使用Rails 4,rpsec和工廠女孩
控制器:
def create
@post = Post.new(post_params)
@post.user_id = current_user.id
if @post.save
flash[:success] = "Yay! Post created!"
redirect_to root_path
else
# flash[:error] = @post.errors.full_messages
render 'new'
end
end
測試:
describe '#create' do
post 'create', FactoryGirl.attributes_for(:post, user: @user)
response.should be_successful
end