2011-08-07 9 views
0

當我嘗試轉到localhost:3000/items/new鏈接時,它說它們是ItemsController :: Item中的未初始化的常量錯誤。我不確定問題是什麼。ItemsController中的未初始化常量錯誤:: Item

我Application.html.erb佈局看起來像

<!DOCTYPE html> 
<html> 
<head> 
<title>TestApp</title> 
<%= stylesheet_link_tag :all %> 
<%= javascript_include_tag :defaults %> 
<%= javascript_include_tag "prototype", "effects" %> 
<%= csrf_meta_tag %> 
</head> 
<body> 
<%= @content_for_layout %> 
<%= yield %> 

</body> 
</html> 

new.html.erb視圖

<div id="show_item"></div> 

<%= form_remote_tag :url => { :action, :create }, 
:update => "show_item", 
:complete => visual_effect(:highlight, "show_item") %> 

Name: <%= text_field "item", "name" %><br /> 
Value: <%= text_field "item", "value" %><br /> 
<%= submit_tag %> 
<%= end_form_tag %> 

show.html.erb視圖

Your most recently created item: <br /> 
Name: <%= @item.name %><br /> 
Value: <%= @item.value %><br /> 
<hr> 

items_controller

class ItemsController < ApplicationController 

    def new 
    @item = Item.new 
    end 

    def create 
    @item = Item.create(params[:item]) 
    if request.xml_http_request? 
     render :action => 'show', :layout => false 
    else 
     redirect_to :action => 'edit', :id => @item.id 
    end 
    end 

    def edit 
    @item = Item.find(params[:id]) 

    if request.post? 
     @item.update_attributes(params[:item]) 
     redirect_to :action => 'edit', :id => @item.id 
    end 
    end 
end 
+0

下面的解決方案有幫助嗎? –

回答

2

您需要item.rb的在你的模型文件夾:

item.rb的

class Item < ActiveRecord::Base 
end 

隨着你在那裏如果有需要的任何驗證。