`
xiayw
  • 浏览: 11401 次
  • 来自: ...
最近访客 更多访客>>
社区版块
存档分类
最新评论

《三》Couldn't find Product with ID=list

阅读更多
老郁闷了 以前很简单的功能现在不成了

    [Couldn't find Product with ID=list

    RAILS_ROOT: /home/xia/worktest/shoplet
    Application Trace | Framework Trace | Full Trace

    /home/xia/jruby-1.5.0/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1616:in `find_one'
    /home/xia/jruby-1.5.0/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:1599:in `find_from_ids'
    /home/xia/jruby-1.5.0/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:619:in `find'
    /home/xia/worktest/shoplet/app/controllers/products_controller.rb:18:in `show'

    ]

后来从网上找到 :

    [jruby -S rake routes
    (in /home/xia/worktest/shoplet)
        products GET    /products(.:format)                {:controller=>"products", :action=>"index"}
                 POST   /products(.:format)                {:controller=>"products", :action=>"create"}
    new_product GET    /products/new(.:format)            {:controller=>"products", :action=>"new"}
    edit_product GET    /products/:id/edit(.:format)       {:controller=>"products", :action=>"edit"}
         product GET    /products/:id(.:format)            {:controller=>"products", :action=>"show"}
                 PUT    /products/:id(.:format)            {:controller=>"products", :action=>"update"}
                 DELETE /products/:id(.:format)            {:controller=>"products", :action=>"destroy"}
                        /:controller/:action/:id          
                        /:controller/:action/:id(.:format) ]


原来它不认 list 那就改成 index 吧, 现在还是不明白为什么不能用 list 了
为什么 rake routes 里没有 这个


说说 edit 功能
<% form_tag url_for({ :id => @product,:action=>"update"}) ,:method => :put  do %>

  <%= render :partial => 'form' %>
  <%= submit_tag "Edit" ,:name => nil %>
<% end %>


这里 :method => :put 很重要,如果不写 你就等错吧 特别奇妙的是
它会吧 :action=>"update" 给吞了

所以 delete 也得改  :method => :delete
否则 你怎么都没有办法从 list 上删除  记录
其实因为它没有找到 规则 不给 :method 默认是 post
它找不到 就 会 去掉 action
结果  url 就变成 localhost:3000/products/:id
还会报错




摘录 挂于 routes 的 内容:
引用

自己加的路由一定要 加在  map.resource 前面
因为
单资源rest风格路由规则: map.resource

   我们定义这样一个规则: map.resource :account

   它会帮我们定义怎样的一个路由规则呢? 答案是一个遵循rest风格的路由规则,非常完美。

ruby代码

   1. # maps these actions in the accounts controller: 
   2. class accountscontroller < actioncontroller::base 
   3.     # get new_account_url 
   4.      def new 
   5.        # return an html form for describing the new account 
   6.     end 
   7.    
   8.     # post account_url 
   9.     def create 
  10.       # create an account 
  11.     end 
  12.   
  13.     # get account_url 
  14.     def show 
  15.       # find and return the account 
  16.     end 
  17.    
  18.    # get edit_account_url 
  19.     def edit 
  20.       # return an html form for editing the account 
  21.     end 
  22.   
  23.     # put account_url 
  24.     def update 
  25.       # find and update the account 
  26.     end 
  27.    
  28.    # delete account_url 
  29.     def destroy 
  30.       # delete the account 
  31.     end 
  32.  end



所以 原来我 list 功能不能用就是 我自己加的路由 加在 它后面被它先捕获  url先分析了, 我的公则就没有用了, 改成下面的情况就能正常工作了

    [
    map.connect 'products/list', :controller => 'products', :action => 'list'
      map.resources :products

    ]
 



分享到:
评论

相关推荐

    python LookupError: Couldn't find path to unrar library

    在Python编程中,`LookupError: Couldn't find path to unrar library` 是一个常见的错误,通常出现在尝试使用某个模块或库解压RAR文件时。这个错误提示表明系统无法找到用于处理RAR格式的必要库,例如unrar库。下面...

    kettle执行hive相关ktr时报错: database type with plugin id [HIVE2] couldn't be found!

    java代码执行hive相关ktr时报错: database type with plugin id [HIVE2] couldn't be found! 解决:kettle-core-7.1.0.0-12.jar适配hive后的包。具体步骤请查看...

    tesseract-4.1.0.rar

    三、解决“couldn't find a matching blob”问题 “couldn’t find a matching blob”通常是因为Tesseract无法识别图像中的特定形状或特征。解决这个问题有以下几种方法: 1. 更新字典和语言模型:确保使用最新的...

    sx1276_Rev3 .rar_LORA解调_LoRa调制_lora_sx1276_调制 lora

    SX1276是一款由Semtech公司设计的高性能LoRa(Long Range)调制解调器,被广泛应用于物联网(IoT)领域的远距离无线通信。这个“sx1276_Rev3.rar_LORA解调_LoRa调制_lora_sx1276_调制 lora”压缩包文件包含的是关于...

    VM虚拟机下安装GHOST系统 .pdf

    ### 三、安装GHOST系统 #### 步骤1:设置虚拟机内存 - 调整虚拟机的内存配置,通常情况下,为虚拟机分配256MB以上的内存是比较合理的。 #### 步骤2:启动虚拟机并加载GHOST系统镜像 - 启动虚拟机后,加载GHOST系统...

    ubuntu下kvm 命令行安装64位ubuntu报"Couldn't find hvm kernel for Ubuntu tree."的问题分析

    在Ubuntu环境下使用KVM(Kernel-based Virtual Machine)进行虚拟机的命令行安装时,可能会遇到一个常见的错误提示:“Couldn't find hvm kernel for Ubuntu tree.” 这个问题通常发生在尝试安装64位Ubuntu操作系统...

    FFMPEG: Download failed: 6;"Couldn't resolve host name"

    Couldn't resolve host name&quot;”。这个错误意味着在下载或更新FFmpeg库的过程中,系统无法解析主机名,可能是网络问题、DNS配置错误或是CMake脚本中的URL问题。 首先,我们来理解这个问题的根源。在OpenCV的...

    ubuntu下kvm 命令行安装64位ubuntu报”Couldn’t find hvm kernel for Ubuntu tree.”的问题分析

    1.安装ubuntu时使用的virt-install的配置: virt-install \ --name test4 \ --ram 1024 \ --disk path=/data/01_ubuntu/ubuntu4.img,size=6 \ --vcpus 1 \ --hvm \ --os-type linux \ --network network=default \ ...

    图解VMWARE上安装XP系统、GHOST_版系统

    ### 图解VMWARE上安装XP系统、GHOST版系统 #### 安装虚拟机的好处与应用场景 在介绍具体的安装步骤之前,我们先来了解一下在VMware上安装XP系统以及GHOST版系统的背景知识和意义。 - **客户操作系统与应用程序...

    安装k8s 1.24.0

    * product_uuid 的唯一性,可以使用命令 sudo cat /sys/class/dmi/id/product_uuid 来获取 product_uuid 三、依赖环境配置 在安装 k8s 1.24.0 之前,需要配置以下依赖环境: * 设置主机名,例如使用 hostnamectl ...

    Errno 14 curl#37 - "Couldn't open file /mnt/repodata/repomd.xml

    当遇到"Errno 14 curl#37 - "Couldn't open file /mnt/repodata/repomd.xml""这样的错误时,意味着在尝试使用`yum`执行操作时,系统无法找到必要的元数据文件——`repomd.xml`。这个文件包含了软件仓库的详细信息,...

    Could not find the main class

    "解决 MyEclipse 8.5 中的 “Could not find the main class” 问题" "Could not find the main class" 是一个常见的错误提示,出现于 MyEclipse 8.5 中使用外带的 Tomcat 时,因 JDK 版本问题所引起。下面将详细...

    bootmgr win7引导文件

    windows 7的引导文件

    kettle-core-7.1.0.0-12.jar

    java代码执行hive相关ktr时报错: database type with plugin id [HIVE2] couldn't be found! 解决:kettle-core-7.1.0.0-12.jar适配hive后的包。具体步骤请查看...

    opendcl.rar

    最全autocad对对应版本opendcl库文件32位64位都最全有:OpenDCL.16.arx;OpenDCL.17.arx;OpenDCL.18.arx;OpenDCL.19.arx;OpenDCL.20.arx;OpenDCL.21.arx;OpenDCL.22.arx;OpenDCL.23.arx;...

    PDF文字提取工具 xpdf_pdftotext

    Syntax Error: Couldn't find 'UniGB-UTF16-H' CMap file for 'Adobe-GB1' collection Syntax Error: Unknown CMap 'UniGB-UTF16-H' for character collection 'Adobe-GB1' Syntax Error: Failed to parse font ...

    VM虚拟机+XP系统 安装教程

    VM虚拟机+XP系统 安装教程 详细讲解了虚拟机的安装步骤,请及时查看。

    Could not find agent

    标题 "Could not find agent" 提供的信息看似简短,但实际上是关于在运行或调试软件时遇到的一个常见错误。这个错误通常出现在Java开发环境中,当JVM(Java虚拟机)无法找到指定的Java代理(Java Agent)时会抛出。...

    tr0109 transformer couldn't read the data source 解决方案

    整了两个小时,终于弄明白了这个问题,共享一下。。。。

    boostdesc_bgm.i,vgg_generated_48.i等.zip

    Couldn't connect to server from the Internet. Perhaps direct connections are not allowed in the current network. To use proxy please check/specify these environment variables: - ...

Global site tag (gtag.js) - Google Analytics