回形针 + Active_admin + Rails 3.0.10 多个图像

发布于 2024-12-13 10:43:29 字数 1632 浏览 2 评论 0原文

我有一个回形针和多个图像的杂物,我实现了 active_admin 并且产品更新很好,但是,我不能不上传或编辑多个图像,我的表单是这样的:

form :html => { :multipart => true } do |f|
  f.inputs "Details" do
    f.input :name
    f.input :created_at, :label => "Publish Product at"
    f.input :category
  end

  f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

  f.inputs "Content" do
    f.input :description
  end
  f.buttons
end

并且...

f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

我想上传图像,但是当我创建一个新资产时,默认缺少图像并且未附加正确的图像,我认为因为图像的上传路径不正确。我的资产模型是:

 class Asset < ActiveRecord::Base
   belongs_to :product
   has_attached_file :asset, :styles => { :large => "340x330", :medium => "140x80>", :thumb => "70x70>" },
     :url => "/products/:id/:style/:basename.:extension",  
     :path => ":rails_root/public/products/:id/:style/:basename.:extension"
 end

如何修改我的资产形式以按我想要的方式工作?谢谢你!

I have a crud with paperclip and multiple images' i implement active_admin and the product update fine, but, i can't not upload or edit the multiple images, the form i have is this:

form :html => { :multipart => true } do |f|
  f.inputs "Details" do
    f.input :name
    f.input :created_at, :label => "Publish Product at"
    f.input :category
  end

  f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

  f.inputs "Content" do
    f.input :description
  end
  f.buttons
end

and the...

f.inputs "Images" do
    f.has_many :assets do |p|
      p.input :asset, :as => :file, :input_html => { :multiple => true }, :label => "Image", :hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
      p.input :_destroy, :as=>:boolean, :required => false, :label=>'Remove'
    end
  end

I want to upload images, but when i create a new asset this have a missing image default and not attach the correct image, i think because the path from the images is not correct to upload. My asset model is:

 class Asset < ActiveRecord::Base
   belongs_to :product
   has_attached_file :asset, :styles => { :large => "340x330", :medium => "140x80>", :thumb => "70x70>" },
     :url => "/products/:id/:style/:basename.:extension",  
     :path => ":rails_root/public/products/:id/:style/:basename.:extension"
 end

how i can modify my assets form to work like i want? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流绪微梦 2024-12-20 10:43:29

解决方案

嗨,这是解决方案,关键是formtastic中的嵌套属性如何工作...

 form :html => { :multipart => true } do |f|
   f.inputs "Product information" do
     f.input :name
     f.input :description
   end

   f.inputs "Product images" do
     f.has_many :assets do |p|
       p.input :asset, :as => :file, :label => "Image",:hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
       p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
     end 
   end

   f.inputs "Product details" do
     f.input :category, :label => "Category", :hint => "Select one category"
     f.input :height
     f.input :width
     f.input :depth
     f.input :color, :label => "Color", :hint => "Select one color"
     f.input :sku, :label => "SKU"
     f.input :price
   end
   f.buttons
 end

The Solution

Hi, here is the solution, the key are how work the nested attributes in formtastic...

 form :html => { :multipart => true } do |f|
   f.inputs "Product information" do
     f.input :name
     f.input :description
   end

   f.inputs "Product images" do
     f.has_many :assets do |p|
       p.input :asset, :as => :file, :label => "Image",:hint => p.object.asset.nil? ? p.template.content_tag(:span, "No Image Yet") : p.template.image_tag(p.object.asset.url(:thumb))
       p.input :_destroy, :as=>:boolean, :required => false, :label => 'Remove image'
     end 
   end

   f.inputs "Product details" do
     f.input :category, :label => "Category", :hint => "Select one category"
     f.input :height
     f.input :width
     f.input :depth
     f.input :color, :label => "Color", :hint => "Select one color"
     f.input :sku, :label => "SKU"
     f.input :price
   end
   f.buttons
 end
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文