我正在开发一个带有画廊模型和图像模型的应用程序,其中每个画廊都有_and_belong_to_many 图像。
我目前正在开发用于创建/编辑画廊的表格。通过这个表单,我希望用户能够添加现有图像并将新图像上传到图库。经过一番折腾,我能够使用 Rails 的“嵌套模型表单”功能来实现这一点,但从 UI 角度来看,最终结果并不令人满意。
我已经意识到我真正需要的是在我的图库表单中包含一个图像表单的 IFRAME。如何将图像表单包含为 IFRAME,而不包含通常与表单一起呈现的所有周围标记(例如,页眉、标题栏和页脚)?请注意,在下面的代码中,当我在“new_iframe”控制器方法中调用“render”时,我已经在使用“:layout => false”。
这是我的图像资源文件:
ActiveAdmin.register Image do
controller.authorize_resource
scope_to :current_admin_user
collection_action :new_iframe, :method => :get do
@image = Image.new
render :action => :new, :layout => false
end
controller do
...
end
index do
column :title do |image|
link_to image.title, edit_admin_image_path(image)
end
column :image do |image|
image_tag(image.thumb_path, :alt => "")
end
column :created_at
column :updated_at
default_actions
end
form :html => { :enctype => "multipart/form-data" } do |a|
a.inputs "Image", :multipart => true do
a.input :title
a.input :asset, :as => :file
end
a.buttons
end
end