#..Rails 4的未定义方法`model_name_question’

我在提交表单后收到此错误:(在索引页面中)

   3, :style => "width:80%", :placeholder => "enter your question." %>   

我有question模型:

 class Question < ActiveRecord::Base validates :question, presence: true belongs_to :category belongs_to :questioner end 

和问题控制器:

 class QuestionsController < ApplicationController def index @quiz = Question.new @questioner = Questioner.new end def new @quiz = Question.new(quiz_params) end def show @quiz = Question.find(params[:id]) end def edit @quiz = find(params[:id]) raise "Question Not edited!" unless @quiz end def create @quiz = Question.new(quiz_params) if @quiz.save flash[:success] = 'You have successfully posted the questions!' redirect_to questions_path else flash[:error] = "Please review the problems below." # render 'new' redirect_to questions_path end end private def quiz_params params.require(:question).permit(:content, :answered, :questioner_id, :category_id) end end 

这可能是什么问题? 在rails服务器中我有这个:

 Completed 500 Internal Server Error in 5ms NoMethodError - undefined method `question' for #: activemodel (4.0.2) lib/active_model/attribute_methods.rb:439:in `method_missing' 

该问题可能与此validation行有关

 validates :question, presence: true 

它假设您的问题模型具有:question属性。 换句话说,确保questions数据库表中有一个正确的question数据库列。

如果不是这种情况,请相应地修复表或validation。