{"id":128,"date":"2008-08-22T13:48:05","date_gmt":"2008-08-22T21:48:05","guid":{"rendered":"http:\/\/www.antunkarlovac.com\/blog\/?p=128"},"modified":"2008-08-22T13:48:05","modified_gmt":"2008-08-22T21:48:05","slug":"using-the-form_for-method-with-multipart-in-rails","status":"publish","type":"post","link":"https:\/\/www.antunkarlovac.com\/blog\/2008\/08\/22\/using-the-form_for-method-with-multipart-in-rails\/","title":{"rendered":"Using the form_for Method with multipart in Rails"},"content":{"rendered":"<p>If you&#8217;re going to upload files via an HTML form, the form&#8217;s encoding must be set to <strong>multipart\/form-data<\/strong>. In Rails, you use a helper method to generate the form tags, so you can&#8217;t directly edit them. The preferred helper is <a href=\"http:\/\/api.rubyonrails.org\/classes\/ActionView\/Helpers\/FormHelper.html\" target=\"_blank\">form_for<\/a>; that&#8217;s what scaffold generates.<\/p>\n<p>Normally, a form_for call would look like this:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n&lt;% form_for(@entry) do |f| %&gt;\r\n  &lt;!-- Form fields --&gt;\r\n&lt;% end %&gt;\r\n<\/pre>\n<p>To make this form be multipart, change the call to the following:<\/p>\n<pre class=\"brush: ruby; title: ; notranslate\" title=\"\">\r\n&lt;% form_for(@entry, :html =&gt; {:multipart =&gt; true}) do |f| %&gt;\r\n  &lt;!-- Form fields --&gt;\r\n&lt;% end %&gt;\r\n<\/pre>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re going to upload files via an HTML form, the form&#8217;s encoding must be set to multipart\/form-data. In Rails, you use a helper method to generate the form tags, so you can&#8217;t directly edit them. The preferred helper is form_for; that&#8217;s what scaffold generates. Normally, a form_for call would look like this: To make &hellip; <a href=\"https:\/\/www.antunkarlovac.com\/blog\/2008\/08\/22\/using-the-form_for-method-with-multipart-in-rails\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Using the form_for Method with multipart in Rails<\/span><\/a><!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/128"}],"collection":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/comments?post=128"}],"version-history":[{"count":1,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":129,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/posts\/128\/revisions\/129"}],"wp:attachment":[{"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/media?parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/categories?post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.antunkarlovac.com\/blog\/wp-json\/wp\/v2\/tags?post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}