微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ruby-on-rails – 主动管理多个文件/图像上传与回形针

我使用活动管理员,我需要上传图库很多图像.我该怎么做?
我的代码
class gallery < ActiveRecord::Base
  belongs_to :event
  has_many :images

  attr_accessible :name,:publish,:images,:image,:images_attributes
  accepts_nested_attributes_for :images,allow_destroy: true

  validates :name,presence: true

end

class Image < ActiveRecord::Base
  belongs_to :gallery

  attr_accessible :url
  has_attached_file :url,:styles => { :medium => "300x300>",:thumb => "100x100>" }
end


ActiveAdmin.register gallery do
    form html: { multipart: true }  do |f|
          f.inputs  do
            f.input :name
            f.input :images,as: :file,input_html: { multiple: true}
          end            
          f.buttons
    end  
end

我有这个错误

Image(#70319146544460) expected,got Actiondispatch::Http::UploadedFile(#70319105893880)

解决方法

尝试这个:
ActiveAdmin.register gallery do
  form multipart: true do |f|
    f.inputs do
      f.input :name

      f.has_many :images do |p|
        p.input :url
      end
    end

    f.actions
  end
end

原文地址:https://www.jb51.cc/ruby/265887.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐