未初始化的常量HomeController

ona*_*000 10 ruby-on-rails

好的,我一直关注:http: //railscasts.com/episodes/196-nested-model-form-part-1

以下是我到目前为止必须完成的步骤:

rails new survey
<install the script stuff he includes>
rails g nifty:layout
rails g nifty:scaffold survey name:string
rake db:migrate
Run Code Online (Sandbox Code Playgroud)

我更新了routes.rb以指向home #index(而不是那个欢迎的#index)并删除了public/index.html

当我尝试运行rails服务器并转到我的本地主机时,出现以下错误.未初始化的常量HomeController

我迷路了,不知道这意味着什么.

有人能指出我正确的方向吗?

编辑:

好的,所以我解决了这个问题,我猜我困惑的地方是我的路线应该指向哪里来查看我刚刚使用上述命令创建的调查.现在我指的是我家的#index,应该指向哪里?

编辑#2:Surveys_controller.rb的内容

class SurveysController < ApplicationController
  def index
    @surveys = Survey.all
  end

  def show
    @survey = Survey.find(params[:id])
  end

  def new
    @survey = Survey.new
  end

  def create
    @survey = Survey.new(params[:survey])
    if @survey.save
      flash[:notice] = "Successfully created survey."
      redirect_to @survey
    else
      render :action => 'new'
    end
  end

 def edit
    @survey = Survey.find(params[:id])
  end

  def update
    @survey = Survey.find(params[:id])
    if @survey.update_attributes(params[:survey])
      flash[:notice] = "Successfully updated survey."
      redirect_to @survey
    else
      render :action => 'edit'
    end
  end

  def destroy
    @survey = Survey.find(params[:id])
    @survey.destroy
    flash[:notice] = "Successfully destroyed survey."
    redirect_to surveys_url
  end
end
Run Code Online (Sandbox Code Playgroud)

zsa*_*ank 16

使用routes.rb指向home#index,它需要您app/controllers文件夹中的HomeController.

如果你完全按照教程,你可以指向survey#index.查看app/controllers中的surveys.rb,了解哪些页面可用.它们是使用niffty_scaffold脚本生成的.


ona*_*000 8

当你试图指向home #index时,它需要有一些东西,只需运行

rails generate controller home index
Run Code Online (Sandbox Code Playgroud)

解决了这个问题.