2010-06-16 39 views
1

嘗試重新創建{script/generate scaffold},並且我已經獲得了許多Rails基礎知識。我懷疑我需要在某處配置默認產品網址。但我在哪裏做這個?如何設置我的@ product = Product.find(params [:id])以擁有product_url?

設置:

  1. 有:DEF編輯{@產物= Product.find(PARAMS [:ID])}
  2. 有無edit.html.erb,具有編輯形式張貼到行動=>:創建
  3. 有無DEF創建{...},與代碼redirect_to的(@product,...)
  4. 四處錯誤:未定義的方法`product_url」爲#<的ProductsController:0x56102b0>

我DEF更新:

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 
+0

ohh,這是你誰回答了這個問題:) – 2010-06-16 20:31:36

回答

2

啊,加入/config/routes.rb行:

map.resources :products 

並確保您將其放在默認值以上:

map.connect ':controller/:action/:id' 
map.connect ':controller/:action/:id.:format' 

這定義了一個系統,用於提供:產品的網址。

相關問題