0

The problem is this: I am showing some data to the user in a table and in it has a field of the numeric type that the user fills. However, I do not know how to send the value populated by the user as a parameter to the controller.

I've tried using the following syntax:

<td><%= number_field :stock, params[:amount] %></td> ## HERE IS THE PROBLEM

<td><%= link_to 'Buy', new_transaction_path(stock: {stock_id: "#{stock[:id]}", buy_price: "#{stock[:value]}", amount: "#{params[:amount]}", transaction_type: 'buy'}), method: :post %></td>

I would like to pass the value that the user informed thought the number_field as a parameter to the controller, but it's not working..

Eduardo Humberto
  • 425
  • 2
  • 5
  • 16

1 Answers1

0

For your case "that the user fills", You have to user a form with a submit button, Here is a relate question, If the value is determined you can use link_to otherwise a form is better, Although sometimes I rely on JS or Jquery, I give the link_to a specific id and I give the input field and id too (HTML id), Then make an action listener on the the <a> that link_to generates, Once user click on it I get the data and submit the data.

The problem for the JS way is that if you are listing a table for more than one link_to for the product with multiple numeric_field you have to make sure that the id is unique, you can simply doing this by adding _#{id} part to the generated id.

Amr Adel
  • 574
  • 1
  • 7
  • 18