2011-10-24 90 views
2

我正在開發一個帶有圖庫模型和圖像模型的應用程序,其中每個圖庫has_and_belong_to_many圖像。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 
+0

我會*如果嵌入式IFRAME文檔中的表單字段在提交表單時包含在參數中,那麼會很驚訝。你有沒有測試過,這是一個非常簡單的HTML表單字段,首先? –

+0

喬恩,這個想法是,IFRAME具有自己的形式和自己的提交按鈕,允許它獨立於周圍的表單提交。你是正確的,內部表單域不會與周圍的表單一起提交。 –

回答

0
模型文件

(其中媒體是你的畫廊模式)

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 
相關問題