1

I am using trestle for admin in a Rails project.

I have Teachers with many Students. There is a proper has_many and belongs_to association. I have everything working nicely in tabs, In one tab I have teacher information and in the other tab I want to display all their students. I have tried coding by guessing because there are no docs, and I have gotten nowhere. But here.

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   
... 

Thanks for any suggestions.

Oskars Ezerins
  • 376
  • 3
  • 11
gofly
  • 13
  • 4

1 Answers1

2

You can do it like this:

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

And in Your example it would be something of the sort:

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   
... 
Oskars Ezerins
  • 376
  • 3
  • 11
  • Hey! This worked perfect, thanks do much. Did you figure this out trial & error or are there some docs somehwere? I'd upvote this answer - but it won't let me - too new! haha – gofly Nov 19 '20 at 22:43
  • Welcome. I looked up in the Trestle repo. They have a couple of issues where they discuss this. Also, they have an example app repo from which you can check example code. – Oskars Ezerins Nov 20 '20 at 06:38