未初始化的常量ProductsController ::提供错误?
我有一个问题,我无法弄清楚产品控制器错误是什么问题, 我不会呈现产品索引视图页面,这是我想要的工作。未初始化的常量ProductsController ::提供错误?
我的代码是在这里如下: 提供控制器
class OffersController < ApplicationController
attr_accessible :product , :reserve_price
def your_offer
@your_offer = Offer.new
end
def new
@offer = Offer.new = :your_offer
end
end
和产品控制器
class ProductsController < ApplicationController
before_filter :authenticate, :except => [:index, :show]
# GET /products
# GET /products.xml
def index
@offer = Offer.new
@products = Product.search(params[:search_query])
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @products }
end
end
# GET /products/1
# GET /products/1.xml
def show
@product = Product.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @product }
end
end
# GET /products/new
# GET /products/new.xml
def new
@product = Product.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @product }
end
end
# GET /products/1/edit
def edit
@product = Product.find(params[:id])
end
# POST /products
# POST /products.xml
def create
@product = current_user.products.new(params[:product])
respond_to do |format|
if @product.save
format.html { redirect_to(@product, :notice => 'Product was successfully created.') }
format.xml { render :xml => @product, :status => :created, :location => @product }
else
format.html { render :action => "new" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
# PUT /products/1
# PUT /products/1.xml
def update
@product = Product.find(params[:id])
respond_to do |format|
if @product.update_attributes(params[:product])
format.html { redirect_to(@product, :notice => 'Product was successfully updated.') }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @product.errors, :status => :unprocessable_entity }
end
end
end
# DELETE /products/1
# DELETE /products/1.xml
def destroy
@product = Product.find(params[:id])
@product.destroy
respond_to do |format|
format.html { redirect_to(products_url) }
format.xml { head :ok }
end
end
end
发售型号
class Offer < ActiveRecord::Base
belongs_to :product
has_many :reserve_prices
attr_accessible :product, :offer , :reserve_price
validates_presence_of :offer
validate :ensure_meets_reserve_price
private
def ensure_meets_reserve_price
if amount < self.product.reserve_price
errors.add(:amount, "does not meet reserve price")
end
end
private
def reserve_price
product.reserve_price
end
def your_offer
@your_offer = Offer.new
end
def new
@offer = Offer.new = :your_offer
end
end
产品指标viex片断
<%= form_for @offer do |f| %>
<%= f.text_field :your_offer %>
<%= f.submit "Make Offer" %>
<% end %>
任何人都可以看到我的错误在哪里吗?
其抱怨@offer = Offer.new
你运行迁移和创建报价后,重新启动服务器?
你有没有宣布它在配置/ routes.rb中的资源作为
resources :products, :shallow => true do
resources :offers # or at least just this line
end
编辑:
摆脱这一行的,然后再试一次
attr_accessible :product, :offer , :reserve_price
是:在优惠表中提供一列?
您不能在attr_accessible中存在来自其他模型的列。
是的,我完成了所有你说的,仍然是相同的错误 – user1555321 2012-07-26 18:01:29
它是产品表中的reserve_price列,我希望我的验证是再次。也即时尝试有产品添加到购物车一旦验证,所以它不必在表等存储任何提供一旦valiadted添加到卡,如果不尝试再等,我删除该行,仍然是相同的错误 – user1555321 2012-07-26 20:27:49
有没有表为产品,这是一个产品表与产品属性,其中包括一个保留价格的列,我试图建立控制器和模型来处理这件事,因为注意到需要保存到表格作为“offer”只是验证了reseve价格,如果accpeted添加到购物车。 – user1555321 2012-07-26 23:34:14
任何人????????? – user1555321 2012-07-30 12:12:48
您的优惠定义文件的名称是什么? 它应该是offer.rb insice应用/模型 – carlosavoy 2013-09-14 19:08:45