Personally, I would view the Receipt Summary as its own class, maybe 
ReceiptRpt::ReceiptSummary.  I'd probably do the work currently in your 
receiptsummary method in the initialize method, then store the values that 
you need in your view in instance variables, and define attr_readers for 
them.  Example:

class ReceiptRpt::ReceiptSummary
 attr_reader :share_amt, :loan_balance

 def initialize(fdate, tdate)
  # ... do work and assign @share_amt, @loan_balance,
  # and any other data you need access to later on
 end
end

Usage:

@summary = ReceiptRpt::ReceiptSummary.new(Date.new(2016, 5, 1), Date.new(
2016, 5, 31))

@summary.share_amt #=> Share Amount
@summary.loan_balance #=> Loan Balance


On Tuesday, June 21, 2016 at 1:50:03 AM UTC-4, Padmahas Bn wrote:
>
> Hello everyone,
>
> I have a situation where I need to send processed data from model to view.
>
> Current working mechanism is,
> View (_form.html.erb)
>
> I have a link
> <%= link_to "receipt summary", receipt_rpts_create_path(from_date: 'fdate'
> , to_date: 'tdate'), :class => "btn btn-warning", method: "get" %>
>
> and some other text fields like share_amt, loan_balance etc, *which needs 
> to be updated later based on processed data received from the model.*
>
> which will send from date and to date to the controller (which is I'm not 
> getting in correct format but I've checked whether parameters are received 
> in controller by coding *puts"#{fdate}"* and its showing the output in 
> stdout as fdate). 
>
> Both dates are received using "params[:from_date]" and "params[:to_date] 
> and sent to model through controller as
> Controller (reciept_rpts_controller.rb)
>
> ReceiptRpt.receiptsummary(fdate,tdate)
>
> In the model I've self.receiptsummary(from_date, to_date) method, where I 
> calculate share_amt, loan_balance, etc.
>
> Now after calculating all those required values, I need to send share_amt 
> and loan_balance etc back to view and update the view's text field with 
> these calculated values.
>
> In basic rails app all these values which are processed in values are 
> stored to database and then view (eg: index.html.erb) will fetch data from 
> database and present to view. But in my situation I don't need to store 
> values to database. I want to show them on web page at that moment.
> How can I achieve this functionality?
>
> Thank you.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/6c81bf8e-35b1-4f54-8eb9-60c7d2c5a008%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to