【问题标题】:Multiple image upload with RoR使用 RoR 上传多张图片
【发布时间】:2014-03-19 10:47:21
【问题描述】:

我是 RoR 的新手,所以对于大多数人来说,这可能是 5 分钟的任务。

我想使用回形针上传多张图片 - 最初我将应用设置为使用回形针上传一张图片。我现在添加了一个单独的资产表,并为关系使用了“嵌套属性”,但丢失了错误。

当然,从上传单张图片到为多张图片引入单独的资产表,这一点非常明显并且最有可能与此有关。

应用程序保存在这里。 https://github.com/KiwiChristy/Pinteresting

谢谢

【问题讨论】:

  • 网络研究的努力?

标签: ruby-on-rails paperclip image-upload


【解决方案1】:

表格

#app/views/images/new.html.erb
<%= form_for @image do |f| %>
    <%= f.file_field :image %>
    <%= f.file_field :image %>
    <%= f.file_field :image %>
    <%= f.submit %>
<% end %>

控制器

   #app/controllers/images_controller.rb
   def new
      @image = Image.new
   end

   def create
      @image = Image.new(image_params)
   end 

   private

   def image_params
      params.require(:image).permit(image: [])
   end

型号

#app/models/image.rb
Class Image < ActiveRecord::Base
    has_attached_file :image
end

好资源:https://gist.github.com/patrickberkeley/33011

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-16
    • 2017-04-08
    • 2011-12-10
    • 2015-02-17
    • 2016-01-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多