2011-08-07 13 views
0

localhost:3000/items/newリンクに移動しようとすると、ItemsController :: Itemの初期化されていない定数エラーと表示されます。私は問題が何であるか分かりません。ItemsController :: Itemの未初期化定数エラー

私Application.html.erbレイアウトが

items_controller
<!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> 

のように見えます

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が必要になります。

class Item < ActiveRecord::Base 
end 

item.rbあれば、あなたがそこに必要なものは何でも検証して。

関連する問題