本文介绍了Form_for与:multipart =>真正的吐出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将头像上传"字段添加到我的个人资料页面",但是一旦我向其中添加:html => {:multipart => true}
,它就会吐出语法错误.
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.
<%= form_for(@user), :html => { :multipart => true } do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.email_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.label :avatar %>
<%= f.file_field :avatar %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
错误是:
syntax error, unexpected tASSOC, expecting keyword_end
...end= form_for(@user), :html => { :multipart => true } do |f...
... ^
推荐答案
http://guides.rubyonrails.org/form_helpers.html#uploading-files
它是带有multipart => true
的form_tag
助手,或者仅仅是form_for
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 %>
这篇关于Form_for与:multipart =>真正的吐出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!