What have you done with Phoenix so far?
For example, it would be helpful if you are already familiar with Building Forms, Programming Phoenix ≥ 1.4 p.60. Fundamentally with HTML the create
action is a result of a form being submitted.
resources "/contracts", ContractController
creates among others a POST /contracts HelloWeb.ContractController :create
route which typically the form inside the page loaded with /contracts/new
submits to. When that submit happens, the information inside the form is sent to the server as form data. The form data is essentially a list of key/value pairs - Phoenix turns those key/value pairs into a single Elixir Map. That map is supplied as the second (params
) parameter to the create
action inside the ContractController
.
Given the above the simplest approach is to represent the retailers as radio buttons (the value being the retailer_id
) inside a form. That way the retailer_id
should appear in create
’s params
map value. The current user should be available in the (first) conn
argument (conn.assigns.current_user
) giving you the necessary information.
Don’t forget to redirect at the end to let the user know whether the “contract create” failed or succeeded.