开发者

Uninitialized Constant error in ItemsController::Item

When I try to go to the localhost:3000/items/new link it says their is an uninitialized constant error in ItemsController::Item. I'm not sure what the problem is.

my Application.html.erb layout looks like

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

<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 view

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.开发者_StackOverflowpost?
      @item.update_attributes(params[:item])
      redirect_to :action => 'edit', :id => @item.id
    end
  end
end


You need item.rb in your models folder:

item.rb

class Item < ActiveRecord::Base
end

With whatever validations you need in there if any.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜