首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将@product=Product.find(params[:id])设置为具有product_url?

如何将@product=Product.find(params[:id])设置为具有product_url?
EN

Stack Overflow用户
提问于 2010-06-16 20:17:58
回答 1查看 408关注 0票数 1

尝试重新创建{script/Generate支架},我已经了解了许多Rails基础知识。我怀疑我需要在某个地方配置默认产品url。但我该在哪做这个呢?

设置:

ProductsController:0x56102b0>有: def编辑{ @product=Product.find(params:id) }

  • edit.html.erb,编辑表单发布到操作=>:create

  • def def create{. },代码redirect_to(@product,.)

  • 获取错误:未定义方法`product_url‘for #<

我的def更新:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-06-16 20:25:16

啊,添加/config/routeres.rb行:

代码语言:javascript
复制
map.resources :products

并确保将其置于默认值之上:

代码语言:javascript
复制
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'

这定义了一个用于给予:产品的urls的系统。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3056867

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档