2012-07-26 26 views
0

我有一個問題,我無法弄清楚產品控制器錯誤是什麼問題, 我不會呈現產品索引視圖頁面,這是我想要的工作。未初始化的常量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 %> 

任何人都可以看到我的錯誤在哪裏嗎?

+0

任何人????????? – user1555321 2012-07-30 12:12:48

+0

您的優惠定義文件的名稱是什麼? 它應該是offer.rb insice應用/模型 – carlosavoy 2013-09-14 19:08:45

回答

0

其抱怨@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中存在來自其他模型的列。

+0

是的,我完成了所有你說的,仍然是相同的錯誤 – user1555321 2012-07-26 18:01:29

+0

它是產品表中的reserve_price列,我希望我的驗證是再次。也即時嘗試有產品添加到購物車一旦驗證,所以它不必在表等存儲任何提供一旦valiadted添加到卡,如果不嘗試再等,我刪除該行,仍然是相同的錯誤 – user1555321 2012-07-26 20:27:49

+0

有沒有表爲產品,這是一個產品表與產品屬性,其中包括一個保留價格的列,我試圖建立控制器和模型來處理這件事,因爲注意到需要保存到表格作爲「offer」只是驗證了reseve價格,如果accpeted添加到購物車。 – user1555321 2012-07-26 23:34:14