是否可以将嵌套表单添加到#show页面?
现在我有了我的 admin/posts.rb:
ActiveAdmin.register Post do
show do |post|
h2 post.title
post.comments.each do |comment|
row :comment do comment.text end
end
end
end
它列出了帖子的所有评论。
现在我需要一个表格来添加新评论。
我正在尝试这样做:
ActiveAdmin.register Post do
show do |post|
h2 post.title
post.comments.each do |comment|
row :comment do comment.text end
end
form do |f|
f.has_many :comments do |c|
c.input :text
end
end
end
end
并得到一个错误:
的未定义方法 `has_many' :Arbre::HTML::Form
帖子和评论的模型如下所示:
class Post < ActiveRecord::Base
has_many :comments
accepts_nested_attributes_for :comments
end
class Comment < ActiveRecord::Base
belongs_to :post
end
如何将该表格添加到我的展示页面?
谢谢
我为 has_one 关系做了类似的事情:
ActiveAdmin.register Post do
show :title => :email do |post|
attributes_table do
rows :id, :first_name, :last_name
end
panel 'Comments' do
attributes_table_for post.comment do
rows :text, :author, :date
end
end
end
end
如果您不需要索伦斯解决方案的额外灵活性,我打赌您可以使用它。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)