2010-06-16 40 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' 

这定义了一个系统,用于提供:产品的网址。

相关问题