当我尝试转到localhost:3000 / items / new链接时,它表示它们是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 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.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
如果有的话,你需要任何验证。