Form_for with :multipart => true spits out

后端 未结 3 1203
长情又很酷
长情又很酷 2021-01-04 00:38

I am trying to add an Avatar Upload field to my Profile Page, but as soon as I add the :html => {:multipart => true} to it, it spits out an syntax error.<

相关标签:
3条回答
  • 2021-01-04 01:08

    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| %>
    
    0 讨论(0)
  • 2021-01-04 01:09

    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 %>
    
    0 讨论(0)
  • 2021-01-04 01:18

    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.

    0 讨论(0)
提交回复
热议问题