How to submit changeset with association

Hello, I’m trying to add something to my database that contains a has_many association like so

  schema "shipments" do
    field :label, :string
    field :target_date_to_be_shipped, :string
    field :status, :string
    has_many :routes, Route

    timestamps()
  end

I have a new form like so

label


shipping date


status


route
??

I want to set a link under route where they can go to route/new and it will be associated with this shipment. is that possible?

EDIT

something like this in the form is what I was thinking

<div class="form-item">
    <%= label f, :routes %>
    <span><%= link "New Route", to: group_shipment_route_path(@conn, :new, @group, @shipment) %></span>
    <%= error_tag f, :routes %>
  </div>

But is there a way to associate what’s submitted after the link with this shipment?

Isn’t passing in shipment here already doing the association on the URL?

I think you are trying to accomplish what’s been discussed in this posts:

Best regards,

Joaquin Alcerro

2 Likes

@sf8193

Please take a look a this post also:

I made some changes that makes it easier to handle the association.

Hope this helps.

1 Like