narrow-laptop-54609
05/24/2022, 5:34 PMlemon-wall-20836
05/24/2022, 5:34 PMlemon-wall-20836
05/24/2022, 5:34 PMlemon-wall-20836
05/24/2022, 5:34 PMlemon-wall-20836
05/24/2022, 5:34 PMnarrow-laptop-54609
05/24/2022, 5:34 PMnarrow-laptop-54609
05/24/2022, 5:36 PMnarrow-laptop-54609
05/24/2022, 5:37 PMlemon-wall-20836
05/24/2022, 5:38 PMlemon-wall-20836
05/24/2022, 5:38 PMlemon-wall-20836
05/24/2022, 5:38 PMlemon-wall-20836
05/24/2022, 5:39 PMlemon-wall-20836
05/24/2022, 5:40 PMnarrow-laptop-54609
05/24/2022, 5:43 PMlemon-wall-20836
05/24/2022, 5:43 PMlemon-wall-20836
05/24/2022, 5:43 PMlemon-wall-20836
05/24/2022, 5:44 PMnarrow-laptop-54609
05/24/2022, 5:44 PMlemon-wall-20836
05/24/2022, 5:44 PMlemon-wall-20836
05/24/2022, 5:45 PMnarrow-laptop-54609
05/24/2022, 5:46 PMdazzling-lighter-36143
05/25/2022, 5:55 AMnew view.
For example, I have a resource baz, which has the field field :foo, as: :has_many, through: bars. When I create a new foo by clicking Create new foo on the baz resource show view, I would like to pre-populate some of the default values for the new foo fields from the existing baz.
Based on my review of Avo's source, it looks like I can scrap together a solution to this by setting a context with params available, then querying baz by reconstructing an instance of the baz model from the query parameters: via_relation=bazs&via_relation_class=Baz&via_resource_id=1 within the resource definition, effectively using the method Avo's BaseController uses: https://github.com/avo-hq/avo/blob/0fc1f9553acc465e0870aab3ece2e70008f0f4c1/app/controllers/avo/base_controller.rb#L366-L368.
Would there happen to be a cleaner way to do this?lemon-wall-20836
05/25/2022, 8:36 AMdefault field option. you can use it as a block and access the params through Avo::App.paramslemon-wall-20836
05/25/2022, 8:38 AMruby
field :level, as: :text, default: -> {
# Use the params or context object to set a default
puts Avo::App.params.inspect
puts Avo::App.context.inspect
"yes"
}lemon-wall-20836
05/25/2022, 8:38 AMAvo::App.contextlemon-wall-20836
05/25/2022, 8:38 AMlemon-wall-20836
05/25/2022, 8:39 AMlemon-wall-20836
05/25/2022, 8:50 AMAvo::ProductsController for ProductResource) are there just for Rails to know how to generate the routes.loud-jewelry-99127
05/25/2022, 11:21 AM