对于#<问卷调查的未定义方法`Ques_id':0x007fcc490c88f8>

时间:2017-06-20 09:35:36

标签: ruby-on-rails

在我的应用程序调查问卷中,我的控制器在一个数据类型中是t.integer“Ques_id”,它无法在我的索引页面中访问。当我运行索引页面时,我将在调查问卷#index错误中得到NoM​​ethodError。如何解决这个错误?

module.exports = {
  elements: {},
  commands: [{

    compareArrays() {
      var list = [[1,2,3],[3,2,1]];
      //I expect a passed assertion because the values in both arrays are equal
      this.assert.arraysEqual(list);
      return this.api;
    }
  }]
};

控制器

class CreateQuestionnaires< ActiveRecord::Migration
  def up
    create_table :questionnaires do |t|
      #t.column "id", :string, :limit => 25
      t.integer "Ques_id"
      t.string "Qname"
      t.string "Header"
      t.string "Description"
      t.string "username"


    end
  end
   def down
     drop_table :questionnaires
   end
end

索引页面在这里我收到了错误

class QuestionnairesController < ApplicationController
 # layout false
  layout "admin"
    def index
    @questionnaires = Questionnaires.sorted()
    end

  def view
    @questionnaires= Questionnaires.find(params[:id])
  end

  def new
    @questionnaires= Questionnaires.new()
  end

  def create
    # Instantiate a new object using form parameters
    @questionnaires = Questionnaires.new(questionnaires_params)
    # Save the object
    if @questionnaires.save
      # If save succeeds, redirect to the index action
      flash[:notice] = "questions saved successfully."
      redirect_to(:action => 'index')
    else
      # If save fails, redisplay the form so user can fix problems
      render('new')
    end
  end

  def edit
    @questionnaires = Questionnaires.find(params[:id])
  end

  def update
    # Find an existing object using form parameters
    @questionnaires= Questionnaires.find(params[:id])
    # Update the object
    if @Questionnaires.update_attributes(questionnaires_params)
      # If update succeeds, redirect to the index action
      flash[:notice] = "questions updated successfully."
      redirect_to(:action => 'view', :id => @questionnaires.id)
    else
      # If update fails, redisplay the form so user can fix problems
      render('edit')
    end
  end

  def delete
    @Questionnaires= Questionnaires.find(params[:id])
  end

  def destroy
    questionnaires = Questionnaires.find(params[:id]).destroy
    flash[:notice] = "questions '#{Questionnaires.name}' destroyed successfully."
    redirect_to(:action => 'index')
  end


  private

    def questionnaires_params
      # same as using "params[:subject]", except that it:
      # - raises an error if :subject is not present
      # - allows listed attributes to be mass-assigned
      params.require(:questionnaires).permit(:Ques_id,:Qname, :Header, :Description, :visible)
    end

end

1 个答案:

答案 0 :(得分:0)

正在查找表格中的Ques_id列(问卷调查表),该列尚未迁移。所以只有它抛出

 `NoMethodError`

请执行

更新您的数据库
rake db:migrate

将迁移文件中定义的所有必需字段迁移到您的数据库,以便它不会抛出错误。