2012-11-14 37 views
2

我使用activeadmin(0.3.2)和nested_form(0.2.3)。Rails 3.1活動管理和nested_form和link_to_add不工作

我的模型是:

class Event < ActiveRecord::Base 
has_many :event_translations 
attr_accessible :event_translations_attributes 
accepts_nested_attributes_for :event_translations, :allow_destroy => true, 
          :reject_if => proc { |attributes| 
           attributes['title'].blank? and 
            attributes['description'].blank? and attributes['language_id'].blank? 
end 


EventTranslation < ActiveRecord::Base 
belongs_to :event 
belongs_to :language 
attr_accessible :description, :title, :event_id, :language_id 
end 

class Language < ActiveRecord::Base 
attr_accessible :iso, :name 
end 

在我active_admin事件控制器,形式呈現爲一個部分:

form :partial => "form" 

在我的意見,我有以下看法/管理/事件/ _form。 html.erb以下內容:

<%= semantic_nested_form_for [:admin, @event] do |f|%> 
<% f.object.event_translations.build %> 
<%= f.semantic_fields_for :event_translations do |h| %> 
<%=h.inputs "Translations" do %> 
    <%= h.input :language, :required => true, :as => :select, :prompt => "Select a Language", :collection => Language.all %> 
    <%= h.input :title, :label => "Name"%> 
    <%= h.input :description %> 
    <%= h.link_to_remove "Remove Translation" %> 
<% end %> 
<% end %> 

<%= f.link_to_add "Add Translation", :event_translations %> 
... 
<% end %> 

這是呈現字段正常,但link_to_add和link_to_remove沒有點擊做任何事情。 // = require jquery_nested_form被添加到application.js,nested_form gem被正確地包含在gemfile中。

謝謝!

回答

3

解決!

我花在這個小時後恨自己現在...

的解決方案是在active_admin.js代替application.js底部添加

//= require jquery_nested_form 

+0

我也是,謝謝你的解決方案。我整天都在爲此付出 – SreRoR