trestle
trestle copied to clipboard
Associations
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?
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.