Sending enumerative parameter to a route from html template

Hello,
I am a new user in Phoenix world, and apologies for my naive question.
I am trying to generate links to Routes from HTML template like below and create issues while sending parameters. Could anyone suggest to me a suitable way for it?

<h2>Products</h2>

<table class="table" >
    <thead>
        <tr>
            <th>Product Name   </th>
            <th>Quantity  </th>
            <th># of Votes   </th>
            <th>Average Rate</th>
            <th> Link to Rate </th>
        </tr>
    </thead>
    <tbody>

<%= for product <- @products do %>
    <tr>
      <td><%= product.name %></td>
      <td><%= product.quantity %></td>
      <td><%= product.votes %></td>
      <td><%= product.avgrating %></td>
      <td><%= link "link", to: Routes.product_path(@conn, :create, product) %>
    </tr>
<% end %>
    </tbody>
</table>

Hello and welcome,

this route is not valid:

<td><%= link "link", to: Routes.product_path(@conn, :create, product) %>

You may want to link product’s show and edit pages, there:

<td>
  <%= link "show", to: Routes.product_path(@conn, :show, product) %>
  <%= link "edit", to: Routes.product_path(@conn, :edit, product) %>
</td>

:create route is used to post a new product, instead. You can see its usage in templates/product/new.html.eex, when it is assigned as the :action of the rendered form.

1 Like

Problem was not on routes, I guess. I have explicitly defined :create route as get. Anyway, my problem is solved. I have messed up many thing…what naive people do :stuck_out_tongue:. Thanks for help.