将 Rails Gem Active Admin 与关联结合使用
我正在尝试新的 Rails gem http://activeadmin.info/ ,它运行得很好!但是我找不到任何有关如何跨协会使用它的文档。例如:
class Membership < ActiveRecord::Base
belongs_to :course
belongs_to :person
class Course < ActiveRecord::Base
has_many :memberships
has_many :people, :through => :memberships
class Person < ActiveRecord::Base
has_many :memberships
has_many :courses, :through => :memberships
会员资格加入表还包括一些额外的数据(即:出勤率)。我试图向会员显示课程和学生姓名 - 并允许对这些姓名进行过滤/排序。据我发现,Active Admin 不能跨关联工作。有没有其他人成功地做到了这一点,或者找到了另一个能做到这一点的宝石?非常感谢!
I'm trying out the new Rails gem http://activeadmin.info/ and it's working great! However I can't find any documentation on how to use it across associations. For example:
class Membership < ActiveRecord::Base
belongs_to :course
belongs_to :person
class Course < ActiveRecord::Base
has_many :memberships
has_many :people, :through => :memberships
class Person < ActiveRecord::Base
has_many :memberships
has_many :courses, :through => :memberships
The membership join table includes some extra data as well (ie: attendance). I'm trying to show the membership with both the course and student name - and allow filtering / sorting on those names. As far as I have found, Active Admin doesn't work across associations. Has anyone else been successful in doing that, or found another gem that does? Thanks so much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
ingredient.rb
product.rb
不要忘记连接表的迁移(:id 为 false!)
现在在 ActiveAdmin 资源中定义表单,覆盖默认值
ingredient.rb
product.rb
don't forget the migrations for the joining table (:id to false!)
Now define the form in you ActiveAdmin resource, override the default
我已经使用 ActiveAdmin 一段时间了,以下是我如何设法让关联在索引和表单中工作。
我刚刚猜测了下面的一些模型列。另请注意,在形式上。 “人员”部分将显示所有可供编辑的列,而“课程”部分将仅显示指定的列。
我还没有对此进行测试,但您应该能够将这些想法应用到您的案例中。它对我有用。
更新:我刚刚再次阅读了您的问题,并注意到您希望能够对关联列进行排序。我刚刚检查了我的实现,这确实不起作用。我的答案可能对你没用,但无论如何我都会把它留在这里(可能对其他人有帮助)。
I've been playing with ActiveAdmin for a while now, here's how I managed to get associations to work in Indexes and Forms.
I've just guessed some of your model columns below. Also note, in the form. The 'person' section will show all the columns for editing, whereas the 'course' section will just show the specified column.
I haven't tested this, but you should be able to apply these ideas to your case. It's working for mine.
Update: I've just read your question again and noted that you're wanting to be able to sort on the association column. I've just checked my implementation and this indeed is not working. My answer may be useless to you but I'll leave it here anyway (might help someone else).
我自己刚刚开始使用这个 gem,虽然我还没有抽出时间来显示关联信息,但以下是创建关联表单的方法:
这将为您提供带有脚手架的基本表单。
I've just started using this gem myself, and while I haven't gotten around to showing association information, here's how you create a form for associations:
That will give you a basic form with scaffolding.
ingredient.rb
product.rb
migration_xxx.rb
products.rb
ingredient.rb
product.rb
migration_xxx.rb
products.rb