Get data from a form_for submit data to use in another form_for/route

Tags: #<Tag:0x00007f113cbfbc70> #<Tag:0x00007f113cbfbb08> #<Tag:0x00007f113cbfb9c8> #<Tag:0x00007f113cbfb888>


Hello folks,

I have these phoenix routes…

 get "/fetch_data", MyController, :fetch_index
 post "/fetch_preview", MyController, :fetch_preview
 put "/fetch_submit", MyController, :fetch_submit

In fetch_data route I upload a csv file using a template and transform into a struct like my_struct = %my_struct{data:[...], is_valid: true, name: "data"}

Then, I render another template (in fetch_preview function inside MyController) :

render conn, "fetch_preview.html", my_struct: my_struct
      <span> my_struct name: </span> <%= %>

      <span> Is_valid: </span> <%= my_struct.is_valid %>

  <div class="">
    <%= form_for @conn, fetch_path(@conn, :fetch_submit),
                 [as: :fetch], fn f -> %>

     #Here how can I set a data to get in fetch_submit function??
     # @conn = Map.put(@conn,"mydata", my_struct) ??
    <%= submit "Review and Continue the Submit" %>
<% end %>

Here, how can properly set and get the param[“mydata”]???

 def fetch_submit(conn, params) do
    |> Map.get("mydata") #this will raise a `Nil exception`


Maybe You can use assign/3 from Plug.Conn to set the value of my_struct inside the assigns field of the connection.

You can see this thread I'm confused about "assigns" what does it do?


I’m thinking that is not a good idea show a huge list(500+ itens) on template, and then send again to the controller, is can be heavy, maybe save it on backend with a gen server or in a helper database table…