Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Form_for with url, format and html options

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|

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.

like image 687
agmcleod Avatar asked Aug 04 '11 13:08

agmcleod


1 Answers

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|

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.

like image 117
Wukerplank Avatar answered Sep 28 '22 16:09

Wukerplank