Form_for with :multipart => true spits out

老子叫甜甜 提交于 2019-11-30 17:22:51
Benjamin Udink ten Cate

http://guides.rubyonrails.org/form_helpers.html#uploading-files

It's either a form_tag helper with multipart => true or just form_for

<%= form_tag({:action => :upload}, :multipart => true) do %>
  <%= file_field_tag 'picture' %>
<% end %>

<%= form_for @person do |f| %>
  <%= f.file_field :picture %>
<% end %>
Alston

It should be like this:

form_for @user, :html => { :multipart => true } do |f|

The parenthesis in form_for(@user) is actually telling Ruby interpreter the function is invoked with only one parameter, and you can't pass wrong number of arguments in a method in Ruby.

I'm assuming that you're either using 'paperclip' or ''carrierwave' to upload images. So, try this:

<%= form_for @user, : url => users_path, :html => {:multipart => true} do |f| %>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!