Form to change variable for a calculation in the same view

0

I'm starting with Rails.

I have a view that receives information from the database and through methods of a model make several calculations.

For example:

<% @profundidade = 0.5 %>

<% @prnt = 90 %>

<% @analises.each do |analise| %>
  <tr>
    <td><%= valor_duascasas(analise.nctotalcomarea * @profundidade * @prnt) %></td>
  </tr>
<% end %>

I want to create a form that changes this value of @profundidade and @prnt .

    
asked by anonymous 28.02.2015 / 02:57

2 answers

1

You do not do this in the view, but in the controller.

Get the 2 variables as a parameter, perform the calculation and return the data ready for the view.

    
02.03.2015 / 15:21
0

Only complementing the response on parameters. Just send the two variables as a parameter in the url (for example link )

After that, you can access the variables in both the controller and the view, by the params variable and set these default values if you do not receive any. For example:

<% @profundidade = params[:profundidade] || 0.5 %>

<% @prnt = params[:prnt] || 90 %>

PS: I still suggest passing these variables to the controller and only accessing them in the view.

    
06.03.2015 / 00:19