【问题标题】:Rails 3.1 Active admin and nested_form and link_to_add not workingRails 3.1 活动管理员和nested_form 和link_to_add 不起作用
【发布时间】:2012-11-14 19:51:42
【问题描述】:

我正在使用 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"

在我看来,我在 views/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 在点击时没有执行任何操作。 //= 需要将 jquery_nested_form 添加到 application.js 并且nested_form gem 正确包含在 gemfile 中。

谢谢!

【问题讨论】:

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


    【解决方案1】:

    解决了!

    在这上面花了几个小时后,我现在很讨厌自己......

    解决方案是添加

    //= require jquery_nested_form 
    

    active_admin.js 的底部而不是application.js

    【讨论】:

    • 我也是,感谢您的解决方案。我花了一整天的时间
    猜你喜欢
    • 1970-01-01
    • 2013-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    相关资源
    最近更新 更多