好的,我一直在关注:
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
我更新了routes.rb,使其指向home#index(而不是原来的welcome#index),并删除了public/index.html
当我尝试运行Rails服务器并转到本地主机时,出现以下错误。
未初始化的常量HomeController
我迷路了,不知道这意味着什么。
有人可以指出我正确的方向吗?
编辑:
好的,所以我解决了这个问题,我想我很困惑的地方是我的路线应该指向哪里以查看我刚刚使用上述命令创建的调查。现在我要指向我的home#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
最佳答案
当route.rb指向home#index
时,它在您的app/controllers文件夹中需要一个HomeController。
如果您完全按照本教程进行操作,则可以仅指向survey#index
。查看应用程序/ Controller 中的surveys.rb,以查看可用的页面。它们是使用niffty_scaffold脚本生成的。