0
我使用活動管理員,我需要上傳我的項目照片。 我該怎麼辦?我的代碼:使用回形針活動管理員多圖像上傳Rails 5
class Project < ApplicationRecord
has_many :images
accepts_nested_attributes_for :images
end
class Image < ApplicationRecord
belongs_to :project
has_attached_file :image
validates_attachment_presence :image
end
ActiveAdmin.register Project do
permit_params :project_name , :project_location , :project_status , :project_area , :project_prices , :project_info , :project_description , :image , :image_file_name, :image_content_type, :image_file_size, :image_updated_at
index do
column :project_name
column :project_description
actions
end
form :html => { :enctype => "multipart/form-data" } do |f|
f.inputs 'Project Info' do
f.input :project_name
f.input :project_description
end
f.inputs do
f.has_many :images do |p|
p.input :image , as: :file
end
end
f.actions
end
end
有了這段代碼,我可以創建沒有圖像的項目。但我不能添加任何圖像數據庫。 等待幫助!