gpt4 book ai didi

ruby-on-rails - Paperclip + Active_admin + Rails 3.0.10 多张图片

转载 作者:行者123 更新时间:2023-12-03 15:01:27 25 4
gpt4 key购买 nike

我有一个带有回形针和多张图片的 crud,我实现了 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

我想上传图像,但是当我创建一个新 Assets 时,它缺少默认的图像并且没有附加正确的图像,我认为是因为图像的路径上传不正确。我的 Assets 模型是:
 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

我怎样才能修改我的 Assets 表单来像我想要的那样工作?谢谢!

最佳答案

解决方案

嗨,这是解决方案,关键是 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

关于ruby-on-rails - Paperclip + Active_admin + Rails 3.0.10 多张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7974389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com