【问题标题】:Attachinary Form - Image Upload附件表格 - 图片上传
【发布时间】:2015-04-14 15:54:53
【问题描述】:

我目前正在构建一个 Ruby on Rails 应用程序(Ruby 2 - Rails 4)。

我选择 Cloudinary 和 Attachinary 作为我为应用程序上传和存储照片/文档附件的选择。

我已经在我的应用程序中设置了用户模型:

has_attachment :avatar, :accept => [:jpg, :png, :gif]

现在我已经设置好了,我希望创建一个表单来为用户个人资料上传头像。

<div class="row">
    <div class="col-md-4 col-xs-12">
        <div class="profile-image" align="center">
            <img src="<%= asset_path "person.png" %>" width="180px" height="180px" alt=""/>
        </div>

       <div class="dropzone-wrapper">
            <div class="table" class="files" id="previews">
                <div id="file_template" class="file-item">
                    <!-- This is used as the file preview template -->
                    <div class="preview-image">
                        <span class="glyphicon glyphicon-paperclip"></span>
                        <img data-dz-thumbnail />
                    </div>

                    <div class="info-file">
                        <div class="name" data-dz-name></div>
                        <strong class="error text-danger" data-dz-errormessage></strong>
                        <div class="size" data-dz-size></div>
                    </div>

                    <div>
                        <div data-dz-remove class="cancel-btn cancel">
                            <span class="glyphicon glyphicon-remove"></span>
                        </div>
                    </div>
                </div>
            </div>

            <div class="dropzone" id="dropzone">
          Drop new image or click.
          <%= form_for :user, do |f| %>
          <%= attachinary_file_field_tag 'user[avatar]', :user, :avatar %>
          <% end %>
            </div>                
        </div>
    </div>

不走运,我知道我一定做错了什么,只是我无法亲眼看到。

感谢观看。

【问题讨论】:

    标签: ruby-on-rails ruby dropzone.js cloudinary


    【解决方案1】:
    <%= form_for :user, do |f| %>
        <%= attachinary_file_field_tag 'user[avatar]', :user, :avatar %>
    <% end %>
    

    应该是:

    <%= form_for :user, do |f| %>
        <%= f.attachinary_file_field :avatar %>
    <% end %>
    

    【讨论】:

      猜你喜欢
      • 2023-03-29
      • 1970-01-01
      • 2012-10-26
      • 2021-10-09
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 2017-01-29
      • 2018-11-19
      相关资源
      最近更新 更多