https://avo.cool logo
Hello, In the app i've inherited there is a re...
# avo-3
p
Hello, In the app i've inherited there is a resource, of which I need to make a new instance of and as part of that I also need to create an instance of a second model at the same time. I've used
create_success_action
in it's Avo controller to do this like so:
Copy code
page = @record.build_node
    @record.node = page
    @record.save
Unfortunatley it's failing to save as the node instance requires a
template_id
being passed to it for it to save. Is there any way of having a select field of
Template
records showing at the end of my main resource definition that I can use to pass to
build_node
in the
create_success_action
? This should allow my main record
Structure::Page
and node record to both be created successfully at the same time.
m
Thread automatically created by rctneil in #1138182212655788054
l
Hi @purple-park-97233 yes, there is a way 1. Add and configure the template_id field on the avo resource 2. Add an attribute accessor for it on the model , this is currently a hack to force avo to show fields that are not model's attributes on forms 3. Access the template_id value from the params on the controller
p
@loud-jewelry-99127 Thank you so much. This works very nicely!
l
Awesome!