2013-08-25 35 views
0

首先請注意,我正在使用rails 4和activeadmin rails 4分支。 https://github.com/gregbell/active_admin/tree/rails4Activeadmin has_many窗體僅用於顯示和編輯

我有兩個型號pictue這是ploymorphic

class Picture < ActiveRecord::Base 
belongs_to :picture_category 
belongs_to :imageable, polymorphic: true 

mount_uploader :image, ImageUploader 
end 

和船舶

class Ship < ActiveRecord::Base 
    has_many :pictures, as: :imageable 
    accepts_nested_attributes_for :pictures 
end 

而且activeadmin ship.rb

ActiveAdmin.register Ship do 

    form do |f| 
     f.inputs do 
     f.inputs 
     f.has_many :pictures, :sortable => :picture_categories do |ff| 
      ff.input :name 
     end 
     end 
    f.actions 
    end 

controller do 
    def permitted_params 
    params.permit(:ship => [:name, :title, :short_desc, :description, :position, :pictures, :enabled, :ship_provider_id, :picture_category_id, :picture_id]) 
    end 
end 
end 

但結果是這樣的:

enter image description here

  1. 如何才能擺脫刪除按鈕,並已提交
  2. 我怎樣才能讓這種形式只在展示和編輯形式,因爲那不是讓有孩子的感覺父母

請點之前代碼中有什麼錯誤。

+0

我只注意到這條線也應該有f.actions但仍然dosent提交表單 f.has_many:圖片:排序=>:picture_categories做| FF | ff.input:名稱 結束 –

回答

0

我知道如何解決第一個問題/ 您需要插入:提交 action代替您的嵌套資源輸入按鈕。例如:

form do |ship| 
    ship.inputs t(:ship_details) do 
    ship.input :name, :label => t(:name) 
    ship.input :description, :label => t(:description) 
    ship.has_many :pictures do |picture| 
     picture.input :url 
     picture.input :imgdescription 
     picture.actions do 
     picture.action :submit 
     end 
    end 
    end 
end