【问题标题】:Rails - using Trestle/admin to display associated recordsRails - 使用 Trestle/admin 显示关联记录
【发布时间】:2020-11-19 21:06:53
【问题描述】:

我在 Rails 项目中使用栈桥进行管理。

我有很多学生的老师。有一个适当的 has_many 和 belongs_to 关联。我在选项卡中一切都很好,在一个选项卡中我有教师信息,在另一个选项卡中我想显示他们所有的学生。我尝试通过猜测进行编码,因为没有文档,而且我一无所获。但是在这里。

Trestle.resource(:teachers) do
...
  form do |teacher|
    tab :general do
      text_field :name  
      ...(this all works fine)
    end
    tab :students do
      (can't get anything working)
    end   
... 

感谢您的任何建议。

【问题讨论】:

    标签: ruby-on-rails trestle-admin


    【解决方案1】:

    你可以这样做:

    tab :tasks do
      table project.tasks, admin: :tasks do
        column :description, link: true
        column :done, align: :center
        column :created_at, align: :center
        actions
      end
    
      concat admin_link_to("New Task", admin: :tasks, action: :new, params: { project_id: project }, class: "btn btn-success")
    end
    

    在你的例子中,它会是这样的:

    Trestle.resource(:teachers) do
    ...
      form do |teacher|
        tab :general do
          text_field :name  
          ...(this all works fine)
        end
        tab :students do
          table teacher.students, admin: :students do
            column :name, align: :center
            ...(your student object fields)
          end
    
          concat admin_link_to('New Student/s', admin: :students, action: :new, params: { teacher_id: teacher }, class: 'btn btn-success')
        end   
    ... 
    

    【讨论】:

    • 嘿!这工作完美,非常感谢。您是否通过反复试验解决了这个问题,或者是否有一些文档?我会赞成这个答案 - 但它不会让我 - 太新了!哈哈
    • 欢迎。我在 Trestle 仓库中查找。他们在讨论这个问题时有几个问题。此外,他们有一个示例应用程序仓库,您可以从中查看示例代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-26
    相关资源
    最近更新 更多