2

我正在开发一个带有画廊模型和图像模型的应用程序,其中每个画廊都有_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
4

1 回答 1

0

在模型文件中(其中 media 是您的画廊模型)

    accepts_nested_attributes_for :media, 
:reject_if => lambda { |a| a[:image].blank? }, 
:allow_destroy => true  

在活动管理员中

    f.inputs "Media" do
  f.has_many :media do |j|
    j.inputs "media" do
      if !j.object.nil?
        j.input :_destroy, :as => :boolean, :label => "Destroy?"
      end
      j.input :image, :hint => f.template.image_tag(j.object.image.thumb.url(), :width => '100')

    end
  end
end
于 2012-06-25T08:37:59.763 回答