Rails 3.1 Active admin和nested_form以及link_to_add不起作用

时间:2012-11-14 19:51:43

标签: ruby-on-rails activeadmin nested-forms

我正在使用activeadmin(0.3.2)和nested_form(0.2.3)。

我的模特是:

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"

在我的观点中,我有以下观点/ admin / events / _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在点击时正在执行NOTHING。 // = require jquery_nested_form被添加到application.js中,而nested_form gem正确地包含在gemfile中。

谢谢!

1 个答案:

答案 0 :(得分:3)

解决!

我花了好几个小时才开始讨厌自己...

解决方案是添加

//= require jquery_nested_form 

位于active_admin.js的底部,而不是application.js