Passing parent id down to child template

Test phoenix application attempting to pass down the parent ID (pkey) down to a child template form to preserve fkey relationship when I’m creating a new call record. I don’t want to enter that value in the form. Unable to get the parent ID value to populate the child template’s parent ID text field. Everything generated by mix phx.gen.html to allow testing. Clearly missing something here and I’ve poured over on-line docs and but can’t find an answer… Appreciate any help.

#in router…
resources “/vendors”, VendorController #vendors is parent to calls
resources “/calls”, CallController, except: [:new]
resources “/calls/:vendor_id”, CallController, only: [:new]

#in changeset…
schema “calls” do
field :details, :string
field :on_date, :date
field :subject, :string
belongs_to :vendors, Agency.Vendors.Vendor
def changeset(call, attrs) do
|> cast(attrs, [ :on_date, :subject, :details])
|> validate_required([ :on_date, :subject, :details])

#in controller .CallController :new function
def new(conn, %{“vendor_id” => vendor_id} ) do
vendor_id = Integer.parse(vendor_id)
changeset = Calls.change_call(%Call{})
|> Plug.Conn.assign(:vendor_id, vendor_id)
|> render(“new.html”, changeset: changeset)
#in new.html.heex
<%= render “form.html”, Map.put(assigns, :action, Routes.call_path(@conn, :create)) %>

#in form.html.heex

<%= label f, :vendor_id %>
<%= text_input f, :vendor_id %>
<%= error_tag f, :vendor_id %>

First if you post code please use triple-back ticks to format it properly.
Please state what error you are getting or what unexpected behavior you are seeing.

Some things I notice immediately are

The Integer.parse/1 does not return an integer, but a tuple {n,”“}, where n is the integer and the second element the invalid part if any.

If you want to pass multiple values into your Conn you can just add them in the render/3 call, the last parameter takes a keyword list.

Why put the :vendor_id into a separate assign if it needs to be a part of your changeset?

Thanks - messed up in a few places and sorry about code formatting - my bad.
I did finally get it to work. for anyone who’s interested…

in the controller:

 def new(conn, %{"vendor_id" => vendor_id} ) do
    {vendor_id,_} = Integer.parse(vendor_id)
    changeset = Calls.change_call(%Call{vendor_id: vendor_id})
    render(conn, "new.html", changeset: changeset)

thanks again.

Check if your :vendor_id makes into your changes, if you put it like that. I have had issues where it would not be set if it did not change from the initial value you supply.

Also depending on what you want to achieve, you could

changeset = Calls.changeset(%Call{}, %{vendor_id: vendor_id})

This would take care of the integer conversion for you.
Put :vendor_id in the changes.
And if necessary you can check if the changeset is valid?.

Currently if someone sends you an invalid id 123INVALID, your integer conversion will happily continue with 123.