将form_for标记与get方法一起使用 [英] Using form_for tag with get method

查看:102
本文介绍了将form_for标记与get方法一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用get方法提交表单。早些时候,我尝试使用form_tag进行类似操作,但是它可以正常工作,但是现在当我更改为form_for标记时,这似乎不起作用。

I am trying to Submit a form using get method. Earlier I was trying a similar thing with form_tag and it was working but now when I changed to a form_for tag, this doesn't seem to work.

<%- filter_path = params[:action] == "index" ? posts_path : sneak_peek_posts_path %>
<%= form_for(@post_filter, :url=> filter_path, :method => :get) do |f| %>

我遇到无路线错误。

推荐答案

如果需要,可以使用:html 传递原始HTML属性。对于Rails 3:

You can pass the raw HTML attributes using :html if you need to. For Rails 3:

<%= form_for(@post_filter, :url=> filter_path, :html => { :method => 'GET' }) do |f| %>

更新,并在Rails 4中,按照下面的@ andre.orvalho建议,可以直接提供方法参数:

Update and in Rails 4, per @andre.orvalho's suggestion below, the method parameter can be supplied directly:

<%= form_for(@post_filter, url: filter_path, method: :get ) do |f| %>

这篇关于将form_for标记与get方法一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆