Setting values on new
#3827
Closed
manuelmeurer
started this conversation in
General
Replies: 1 comment 1 reply
-
Hi @manuelmeurer 👋 You're on the right track! I'll open a PR to convert those variables into instance variables so they can be accessed externally when needed. In the meantime, I recommend replicating the internal logic used to retrieve the Let me know if you need help with that. class Avo::CourseLinksController < Avo::ResourcesController
def new
super
if is_associated_record?
via_resource = Avo.resource_manager.get_resource_by_model_class(params[:via_relation_class])
via_record = via_resource.find_record params[:via_record_id], params: params
# Assign course_name from parent record (course)
@record.course_name = via_record.name
end
end
end |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have models
User
andMessage
, and a user has many messages.When I create a new message for a user, I would like to set the message's email field to the user's email.
How do I do that with Avo?
My first idea was to override the
new
action in theAvo::MessagesController
and set the value there:Looking at the source for
Avo::BaseController
, I would need to accessvia_record
, but I can't, probably because it's not an instance variable?Or is there any easier way to do this that I missed?
Beta Was this translation helpful? Give feedback.
All reactions