nig*_*f0x 12 ruby routes ruby-on-rails
我正在尝试使用get方法提交表单.早些时候我正在尝试使用form_tag进行类似的操作并且它正在运行但是现在当我更改为form_for标签时,这似乎不起作用.
<%- filter_path = params[:action] == "index" ? posts_path : sneak_peek_posts_path %>
<%= form_for(@post_filter, :url=> filter_path, :method => :get) do |f| %>
Run Code Online (Sandbox Code Playgroud)
我得到一个无路由错误.
rjz*_*rjz 24
:html如果需要,可以使用原始HTML属性.对于Rails 3:
<%= form_for(@post_filter, :url=> filter_path, :html => { :method => 'GET' }) do |f| %>
Run Code Online (Sandbox Code Playgroud)
更新并在Rails 4中,根据@ andre.orvalho的建议,method可以直接提供参数:
<%= form_for(@post_filter, url: filter_path, method: :get ) do |f| %>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13798 次 |
| 最近记录: |