Rails 3.2.9正在生成模板缺失错误

时间:2013-02-01 22:50:29

标签: ruby-on-rails-3

我在Rails 3.2.9中遇到以下错误:

Template is missing

Missing template projects/create, application/create with {:locale=>[:en], :formats=>[:html], :handlers=>[:erb, :builder, :coffee]}. Searched in: * "c:/Documents and Settings/.../app/views"

昨天我开始收到此错误,回去重建我的控制器并仍然收到错误。然后我在命令行上使用rails generate scaffold重建了所有内容。当我进入保存新对象实例时,我仍然遇到同样的错误。

我的假设是脚手架生成器会以简单的方式生成正确的代码,然后让我一块一块地重建功能。

我在下面包含模型和控制器的代码:

class Project < ActiveRecord::Base
  attr_accessible   :title, ...

end

++++++++++

class ProjectsController < ApplicationController

  # GET /projects
  def index
    @projects = Project.all


  end

  # GET /projects/1
  def show
    @project = Project.find(params[:id])


  end

  # GET /projects/new
  def new
    @project = Project.new


  end

  # GET /projects/1/edit
  def edit
    @project = Project.find(params[:id])
  end

  # POST /projects
  def create
    @project = Project.new(params[:project])
    @project.save

  end

  # PUT /projects/1
  def update
    @project = Project.find(params[:id])


  end

  # DELETE /projects/1
  def destroy
    @project = Project.find(params[:id])
    @project.destroy


  end
end

有人有什么想法吗? Rails一夜之间发生了错误吗?我无法找到任何使用Google-Fu的内容。 感谢。

1 个答案:

答案 0 :(得分:2)

不确定rails中的默认rails脚手架,但通常你应该使用成功的flash消息重定向create:

@project = Project.new(params[:project])
if @project.save
  redirect_to @project, notice: "Success"
else
  render :new
end