ActiveAdmin:在另一个表单中将表单显示为 IFRAME
我正在开发一个带有图库模型和图像模型的应用程序,其中每个图库都有并且属于许多图像。
我目前正在开发用于创建/编辑画廊的表单。通过此表单,我希望用户能够添加现有图像并将新图像上传到图库。经过一番思考,我能够使用 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
I am developing an application with a Gallery model and an Images model, where each gallery has_and_belong_to_many images.
I'm currently developing the form for creating/editing a gallery. From this form, I would like users to be able to both add existing images and upload new images to the gallery. After much mucking about, I was able to use the Rails "nested model forms" functionality to achieve this, but the end result was unsatisfactory from a UI perspective.
I've realized that what I really need is an IFRAME in my gallery form that contains an image form. How can I include the image form as an IFRAME without all the surrounding markup that is normally rendered along with the form (e.g., the header, the title bar, and the footer)? Note in the code below that I am already using ":layout => false" when I call "render" in my "new_iframe" controller method.
Here is my Image resource file:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
模型文件中(其中媒体是您的图库模型)
在活动管理的
in the model file (where media is your gallery model)
in active admin