ruby-on-rails – Form_for with:multipart => true吐出

前端之家收集整理的这篇文章主要介绍了ruby-on-rails – Form_for with:multipart => true吐出前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图添加一个头像上传字段到我的个人资料页面,但一旦我添加:html => {:multipart => true},它会吐出语法错误.
<%= 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

它是一个form_tag帮助器,multipart =>真或只是form_for

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

<%= form_for @person do |f| %>
  <%= f.file_field :picture %>
<% end %>
原文链接:https://www.f2er.com/ruby/273434.html

猜你在找的Ruby相关文章