Calculating values after rendering page in rails

Hi all… I am trying to generate a report which has multiple columns…
After rendering the report I allow the user to enter a value which is to
be subtracted from the column which is already rendered… I have
multiple rows… so I have tries like the following. My views page is

<% @arr.each do |j| %>
<% @q =[] %>
<% t= 0 %>
<%= form_for ProductionReport.new
,:url=>{:controller=>“users”,:action=>“rate_per_unit_report” } do |i| %>

<%= j[0] %> <%= j[1] %> <%= j[2] %> <% @q < <%= i.text_field j[3], :value=>@q[t], :id=>"txt1", :onkeyup=>"sum()", :class=>"txt" %> <%= i.text_field :selling_price, :id=>"txt2", :onkeyup=>"sum()", :class=>"txt" %> <%= i.text_field :profit_loss, :id=>"txt3", :class=>"txt", :readonly =>true %> <% end %> <% t = t+1 %> <% end %> total <%= @total %> <%= @total1 %> <%= @total2 %>

My controller is

def rate_per_unit_report
@user=User.new
@user = User.find(session[:user_id]).name
@rpus = params[:production_report][:intial_date]
@rpue = params[:production_report][:final_date]
@production_report = ProductionReport.where(:date => @rpus@rpue)
@production = @production_report.select(:finished_goods_name).uniq
@arr=[]
g = 0
@production.each do|i|
@p = @production_report.pluck(:issue_id)
@ll =
@production_report.where(:finished_goods_name=>i.finished_goods_name).select(:total_no_of_items_produced).sum
:total_no_of_items_produced
@k = Issue.where(:id=>@p).pluck(:consolidated_cost)
@rate = @k[g].to_f / @ll.to_f
@r = @rate.round(2)
@arr<<[i.finished_goods_name]+[@ll]+ [@k[g]] + [@r]
g = g+1
end
@[email protected](0){|sum,x| sum + x[1].to_i }
@[email protected](0){|sum,y| sum + y[2].to_i }
@[email protected](0){|sum,z| sum + z[3].to_i }
end

And my sample output page is attached as an image… Pls look at it…

Shortly., I need to dynamically compute profit/loss based on the selling
price entered by the user. How could I achieve that… Kindly pls help
me… Thanks in advance…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs