老郁闷了 以前很简单的功能现在不成了
[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
]
分享到:
相关推荐
UnrarDLL包
java代码执行hive相关ktr时报错: database type with plugin id [HIVE2] couldn't be found! 解决:kettle-core-7.1.0.0-12.jar适配hive后的包。具体步骤请查看...
1. Window10 编译 tesseract 4.1 2. 有效解决 couldn't find a matching blob 问题
SX1276收发器的特点是提供超长范围扩频通信和高干扰的LORA远程调制解调器
VM虚拟机下安装GHOST系统 .pdf
opencv4.1.0使用cmake编译时,提示FFMPEG: Download failed: 6;"Couldn't resolve host name
图解VMWARE上安装XP系统、GHOST_版系统
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 \ ...
最全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;...
主要介绍了ubuntu下kvm 命令行安装64位ubuntu报"Couldn't find hvm kernel for Ubuntu tree."的问题分析的相关资料,需要的朋友可以参考下
在Myeclipse 8.5中用外带的tomcat时候,会因为JDK版本的问题出现Could not find the main class,按照上述文档的步骤就可以解决,我亲自体验过
利用kubeadm安装k8s 1.24.0
libmupdf.so(mupdf1.6)x86 版本32位的需要64位的请不要下载 能有效解决couldn't find "libmupdf.so"问题。
Eclipse 编译时遇到错误could not find the main class,program will exit的解决方法
整了两个小时,终于弄明白了这个问题,共享一下。。。。
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 ...
Could not find Developer Disk Image"问题
NULL 博文链接:https://liuenjian.iteye.com/blog/711927
NULL 博文链接:https://z-one.iteye.com/blog/1058263
OpenCV3.1在CMake时,会出现couldn't to connect server!原因可能是你网络为连接或者是下载过慢导致失败!资源虽然在github上有,但是在不同的branch中,一下不好找。下载解决的办法是把解压ffmpeg dll和fffmpeg_...