TrestleAdmin / trestle

A modern, responsive admin framework for Ruby on Rails
https://trestle.io
GNU Lesser General Public License v3.0
1.96k stars 176 forks source link

Associations #169

Open martio opened 5 years ago

martio commented 5 years ago

Hi,

I have models in my application with the has_many association: car and parts. Car has many parts.

How to go from a car resource to parts?

Trestle.resource(:cars) do
  table do
    column :id
    column :name
    actions do |toolbar, instance, admin|
      toolbar.link 'Parts', "/admin/parts?&q=#{instance.id}", target: '_blank'
    end
  end
end
Trestle.resource(:parts) do
   search do |query|
    if query
      Part.where('car_id = ?', query)
    else
      Part.all
    end
  end

  table do
    column :name
    actions
  end
end

The right way?

karan-ta commented 5 years ago

In cars admin resource - you can add a collectionselect Or collectioncheckbox You will then get a list of parts to select or check in the add new car form. I shall paste code tomorrow morning or you can google for - collection select trestle admin.