带有 url、format 和 html 选项的 Form_for [英] Form_for with url, format and html options

查看:36
本文介绍了带有 url、format 和 html 选项的 Form_for的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得我在这里遗漏了一些简单的东西.我正在使用 form_for 帮助器和一个对象.我指定了 url、格式和 html 方法.但是,当在 action 属性中呈现 url 时,不会选择格式.这是我的代码:

I feel like im missing something simple here. I am using the form_for helper with an object. I specify the url, the format, and html method. However, when rendered the url in the action attribute does not pick up the format. Here's my code:

=form_for(@site, url: compile_documents_path(@site), format: :csv, html: { method: :post}) do |f|

我的控制器设置为响应 csv 格式,我只需在站点对象上调用 to_csv 方法.

My controller is setup to respond to a csv format, and i simply call a to_csv method on the site object.

关于为什么它没有按预期工作的任何想法.

Any ideas as to why it's not working as expected.

推荐答案

未测试,但我认为格式部分应该进入 url helper:

Untested, but I think the format part should go into the url helper:

=form_for(@site, url: compile_documents_path(@site, format: :csv)) do |f|

另外:我认为您不必指定 method::post 部分,因为 form_for 将决定它是否应该使用 PUTPOST,基于@site 是新记录还是现有记录.

Plus: I don't think you have to specify the method: :post part, as form_for will decide if it should use PUT or POST, based on whether @site is a new or an existing record.

这篇关于带有 url、format 和 html 选项的 Form_for的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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