Ruby on Rails: button_to, link_to
来源:互联网 发布:智能排班软件 编辑:程序博客网 时间:2024/06/05 22:49
I have this piece of code:
<%= link_to "New User", new_user_path, :class => "button" %><br />
which works fine, but when I change it to,
<%= button_to "New User", new_user_path, :class => "button" %><br />
I get this error No route matches [POST] "/users/new"
Any help at all will be appreciated. Thanks
EDIT:
<%= button_to "New User", new_user_path, :class => "button", :method => :get %><br />
3 Answers
Jesus Rodriguez is right about POST and GET, but if you really need the button you can simply override the default method:
<%= button_to "New User", new_user_path, :class => "button", :method => :get %>
The "link_to" is looking for a /users/new using GET.
The "button_to" is looking for a /users/new using POST
If you create the routes for a controller using:
resources :user
By default, /users/new is a GET and not POST so, the second line doesn't find any route.
If you are thinking to change that action to POST I think that you should forget about it.
button_to defaults to POST, and link_to defaults to GET, this is why links_to worked. You can force button_to to use GET:
<%= button_to "New User", new_user_path, :class => "button", :method => :get %>
You can get more information about button_to options here: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-button_to
- Ruby on Rails: button_to, link_to
- Ruby on Rails: 给button_to添加图标
- Rails link_to 和 button_to 的区别
- rails中link_to与button_to的一个功能差异
- ruby on rails 给link_to 加action和class,id样式
- Ruby on Rails 在link_to的链接中加入span的tag
- link_to 与button_to 的一些用法
- Ruby & Rails on Rails 進階書單
- ruby and ruby on rails
- install Ruby on Rails
- Ruby on Rails 实践
- Ruby on Rails!
- Ruby on Rails
- 关于Ruby on Rails
- 初探Ruby on rails
- Ruby on Rails
- 了解Ruby on Rails
- Ruby on Rails 是什么?
- 时间会看透一个人
- MVC 详解
- 被遗忘的青春
- 括号匹配问题
- RDD Dependency详解---Spark学习笔记9
- Ruby on Rails: button_to, link_to
- jar 重新打包
- jboss之启动加载过程详解(三)
- ”ssh: connect to host gmail.com port 22: Network is unreachable"的解决办法
- 深入理解PIPE
- 云开发应用实例:微软新战略首推云计算
- 怎样用JAVA调用DLL?
- zoj 3781 Paint the Grid Reloaded
- 烦人的sybase