activeadmin、has_many 和 ckeditor
我在 github 上的 activeadmin 问题板上提出了同样的问题: https://github.com/gregbell/active_admin/issues/645
嗨,
我有两个不同的问题。
1:我喜欢主动管理通过简单的 DSL 处理 has_many 关系的方式,如下所示:
ActiveAdmin.register Artist do
form do |f|
f.inputs do
f.input :name
f.input :description
end
f.inputs "ArtistLinks" do
f.has_many :artist_links do |j|
j.inputs :title, :url
end
end
f.buttons
end
end
在表单底部添加更多链接的能力非常棒。
但是,我一直在使用 wyiswyg,但我似乎无法以这种格式工作。我一直在使用/添加它的一部分,如下所示:
ActiveAdmin.register NewsItem do
form :partial => "/news_items/form"
end
/app/views/news_item/_form.html.erb
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
<%= semantic_form_for [:admin, @news_item], :multipart => true do |f| %>
<%= f.inputs :title, :photo, :excerpt %>
<%= cktext_area_tag("news_item[content]", @news_item.content) %>
<%= f.submit %>
<% end %>
但是, 在我的部分,我似乎无法像这样很好地建立 has_many 关系:
f.inputs "ArtistLinks" do
f.has_many :artist_links do |j|
j.inputs :title, :url
end
end
您能否向我解释一下如何将使用表单助手 cktext_area_tag 的所见即所得的代码放入我的管理资源中,或者向我解释如何获得它好的 has_many 进入我的视图部分吗?
非常感谢!
I'm putting up the same question I asked here in activeadmin's issues board on github:
https://github.com/gregbell/active_admin/issues/645
Hi,
I have two different issues.
1: i love the way active admin handles has_many relationships with a simple DSL like so:
ActiveAdmin.register Artist do
form do |f|
f.inputs do
f.input :name
f.input :description
end
f.inputs "ArtistLinks" do
f.has_many :artist_links do |j|
j.inputs :title, :url
end
end
f.buttons
end
end
The ability to add more links at the bottom of the form is great.
However,I have been using a wyiswyg which i can't seem to get working in this format. I've been using/adding it with a partial like so:
ActiveAdmin.register NewsItem do
form :partial => "/news_items/form"
end
/app/views/news_item/_form.html.erb
<%= javascript_include_tag "/javascripts/ckeditor/ckeditor.js" %>
<%= semantic_form_for [:admin, @news_item], :multipart => true do |f| %>
<%= f.inputs :title, :photo, :excerpt %>
<%= cktext_area_tag("news_item[content]", @news_item.content) %>
<%= f.submit %>
<% end %>
However,
in my partial, i can't seem to be able to make the has_many relationship nicely like so:
f.inputs "ArtistLinks" do
f.has_many :artist_links do |j|
j.inputs :title, :url
end
end
Could you either explain to me how to get my wysiwyg which uses a form helper cktext_area_tag into my admin resource or explain to me how to get that nice has_many into my view partial?
Thanks a bunch!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
has_many
在部分代码中不起作用的原因是,Active Admin 告诉您在编写部分代码时使用semantic_form_for
。 Active Admin 扩展了用于生成表单的 Formtastic。它通过创建自己的表单构建器来实现这一点,该表单构建器扩展了 Formtastic 构建器并添加了has_many
方法等。因此,如果您想在内部使用该部分,则必须使用 Active Admin 表单构建器。为此,请使用active_admin_form_for
而不是semantic_form_for
。如果您在使用
active_admin_form_for
时遇到问题,请查看我的分支,它应该可以解决大多数问题问题的(它仍然是测试版 - 但我正在努力将其纳入 Active Admin 核心)The reason why
has_many
does not work in partials is because Active Admin tells you to usesemantic_form_for
when writing your partial. Active Admin extends Formtastic which it uses to generate forms. It does so by creating its own form builder that extends the Formtastic builder and adds, among others, thehas_many
method. So if you want to use that inside partials you have to use the Active Admin form builder. To do that useactive_admin_form_for
instead ofsemantic_form_for
.If you have problems using
active_admin_form_for
, take a look at my branch which should fix most of the issues (it's still beta - but I'm working on getting it into Active Admin core)