Rails:未初始化的常量类名

时间:2017-06-25 08:15:11

标签: ruby-on-rails ruby ruby-on-rails-4

我遇到了这个问题:

  

未初始化的常量QuestionsController :: Question

def index
    @Question
    @preguntas = Question.all
    @project_id = request.original_url.split('.').last
    set_current_project(@project_id)
    if(@project_id.include? "http")

在我的QuestionController之后,在我的应用程序中没有更改任何内容后,知道可能导致它的原因吗?这里是完整的.rb文件:

class QuestionsController < ApplicationController
before_action :require_user
before_action :require_project
before_action :require_user, except: [:new, :create]
before_action :current_project, only: [:index]
def index
    @preguntas = Question.all
    @project_id = request.original_url.split('.').last
    set_current_project(@project_id)
if(@project_id.include? "http")
@project_id = "0"
end
    if(@project_id != "0")
        @proyecto = Project.find(@project_id)
    end 
end

def show
  @pregunta = Question.find(params[:id])
end

def new
  @pregunta = Question.new
end

def create
  @pregunta = Question.new(pregunta_params)
  if @pregunta.save
     redirect_to @pregunta
  else
     render 'new'
  end
end
 def edit
     @pregunta = Question.find(params[:id])
end 

def update
  @pregunta = Question.find(params[:id])
  if @pregunta.update(pregunta_params)
    redirect_to @pregunta
  else
    render 'edit'
  end
end


 def destroy
    @pregunta = Question.find(params[:id])
    @pregunta.destroy
    flash[:danger] = "Se ha borrado la pregunta"
    redirect_to questions_path
end 


def require_same_user 
    set_project
    if current_user != @project.user && !@current_user.admin?
        flash[:danger] = "Solo puedes editar tus artículos"
        redirect_to root_path
    end 
end 

def require_project
    if current_user.projects.count <1 && !current_user.admin?
        redirect_to root_path
    end 
end 

private
    def pregunta_params
        params.require(:question).permit(:question, :value, :phase, :area, :input)
    end

1 个答案:

答案 0 :(得分:1)

确保在名为Question的文件中定义app/models/question.rb模型,如下所示:

class Question < ApplicationRecord
  # methods...
end
相关问题