关于router restful和button_to
发布日期:2021-09-29 20:08:48 浏览次数:4 分类:技术文章

本文共 2636 字,大约阅读时间需要 8 分钟。

今天费了一些时间啊一个很久之前遇到过的问题又忘了
Rails 3
写了个路由
get "report/index"   get "report/show"
rake routes可以知道
report_index GET    /report/index(.:format)         {:controller=>"report", :action=>"index"}       report_show GET    /report/show(.:format)          {:controller=>"report", :action=>"show"}
于是,就写了个button_to
%h1 Report#show = button_to('click', :action => 'index',:method=>:get)
发现诡异现象,点击就会提示没有路由,地址栏回车就能显示。
我就记着很久之前遇到过这个问题,可是就是想不起来怎么回事。
后来看后台信息和地址栏,发现问题
[quote]http://127.0.0.1/report/show?method=get[/quote]
后台
[quote]
Started POST "/report/index?method=get" for 192.168.1.130 at 2011-05-19 14:04:41 -0400
ActionController::RoutingError (No route matches "/report/index"):
[/quote]
仔细看看API
<%= button_to "New", :action => "new" %> # => "
#
#
" <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete %> # => "
#
#
#
#
#
"
[color=red]发现少了个大括号[/color]
[quote]
button_to(name, options = {}, html_options = {})
Generates a form containing a single button that submits to the URL created by the set of options. This is the safest method to ensure links that cause changes to your data are not triggered by search bots or accelerators. If the HTML button does not work with your layout, you can also consider using the link_to method with the :method modifier as described in the link_to documentation.
The generated form element has a class name of button_to to allow styling of the form itself and its children. You can control the form submission and input element behavior using html_options. This method accepts the :method and :confirm modifiers described in the link_to documentation. If no :method modifier is given, it will default to performing a POST operation. You can also disable the button by passing :disabled => true in html_options. If you are using RESTful routes, you can pass the :method to change the HTTP verb used to submit the form.
Options
The options hash accepts the same options as url_for.
There are a few special html_options:
:method - Symbol of HTTP verb. Supported verbs are :post, :get, :delete and :put. By default it will be :post.
:disabled - If set to true, it will generate a disabled button.
:confirm - This will use the unobtrusive JavaScript driver to prompt with the question specified. If the user accepts, the link is processed normally, otherwise no action is taken.
:remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behaviour. By default this behaviour is an ajax submit.
[/quote]

转载地址:https://blog.csdn.net/horace_lee/article/details/83923800 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:搜索上级dom对象并隐藏,点击隐藏父元素
下一篇:undefined local variable or method `version_requirements'

发表评论

最新留言

不错!
[***.144.177.141]2024年03月28日 07时58分15秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

技校毕业是什么学历_中等职业学校是什么_中等职业学校毕业是什么学历 2019-04-21
英特尔cpu发布时间表_被嘲讽的英特尔核显,强大能力其实超乎你的想象 2019-04-21
chi2inv函数 matlab_MATLAB概率和统计(2) 2019-04-21
lisp修改上一个图素_在Windows上安装Haskell 2019-04-21
ad19 导出step 没有pcb_几款主流PCB软件哪个最好用,你用过几款? 2019-04-21
json mysql 字段 默认值_Newtonsoft.Json 六个超简单又实用的特性,值得一试 【上篇】... 2019-04-21
ocdma相干非相干_《Acconeer 60GHz脉冲相干雷达芯片:A111》 2019-04-21
修改表格字体颜色_Excel技巧:Excel如何修改字体颜色 2019-04-21
native react 变颜色 点击_React Native主动更改StackNavigator标头颜色 2019-04-21
prism项目搭建 wpf_WPF MVVM使用prism4.1搭建 2019-04-21
python发微信红包群_用Python实现微信自动化抢红包,再也不用担心抢不到红包了... 2019-04-21
python中func自定义函数_Python函数之自定义函数&作用域&闭包 2019-04-21
wget连接指定端口_端口通不通 telnet wget ssh 2019-04-21
eureka 调用服务_Spring Cloud微服务架构从入门到会用(二)—服务注册中心Eureka... 2019-04-21
easyexcel 工具类_问了个在阿里的同学,他们常用的15款开发者工具! 2019-04-21
mysql统计结果大于0时返回true_mysql表查询练习 2019-04-21
c语言对结构体排序中间变量,求助:c语言怎么实现结构体的排序? 总是弄不对啊... 2019-04-21
c语言宏定义只能在最前面吗,C语言宏定义注意事项 2019-04-21
android悬浮窗服务卡死,Android 悬浮窗兼容问题谈 2019-04-21
表格相关的html语言,HTML标记语言——表格标记 2019-04-21