that’s a nice broad question - so I’ll give you a broad answer (the very MVP 
with lots of room for optimization)

 :)

(and I’ve probably left one or two BIG mistakes - and my apologies for that)

cheers 
Walther


—— here goes:

if you by report mean a list of, say accounts, each listing eg. transactions 
like this

        sales inland
                q1 - transactions
                        1/1/15  burning red     1,500.00
                        1/3/15  smoothers                       252.75
                q2 - transactions
                        4/21/15 broke back                      975.00

I’d make myself a report action in the accounts controller (like 
/accounts/report) or use the :index action and supply an argument when you call 
it (like /accounts?report=true) or construct a special ‘decorator’-kind of 
controller (like ReportsController) and call it like /reports?accounts=true

Your controller (let’s stick with the ReportsController for now)

  def accounts
    @collection = Account.all.includes :transactions
  end


Add a route in routes.rb

  ressources :reports do
    collection do
      get :accounts
    end
  end

In your views (ie app/views/reports) I would build the report in 
account.html.haml

%table
  %thead
    %tr
      %th t(‘report.account.quarter')
      %th= t(‘report.account.transaction’)
  %tbody
    = @collection.each do |account|
      = render partial: ‘account’, locals: { account: account }

Each account gets built in app/views/accounts/_accoount.html.haml

%tr
  %td= account.title
  %td

- quarter = 1
- account.transactions.sort(:transaction_date) do |transaction|
  - q = find_quarter(transaction)
  - if q > quarter 
    - quarter = q
    %tr
      %td.quarter= “q%s - transactions” % say_quarter transaction
      %td
        %table.transactions
  %tr
    %td.transaction-date= transaction.transaction_date
    %td.transaction-text= transaction.description
    - if transaction.amount < 0
      %td
      %td.transaction-amount= transaction.amount
    - else
      %td{ colspan: ‘2’}.transaction-amount= transaction.amount

Then you could order it with 

        = link_to t(‘report.on-accounts’), “#!”, data: { url: "<on of the url’s 
listed above>”}, class: “report”

And in the bottom of your index.html.haml (or what ever your page with the 
above link is) you’d put

:coffeescript

  $ ->
    $(document.body).on ‘click’, ‘.report’, (e) ->
      elem = $(e.currentTarget)
      window.open elm.data(‘url’)


> Den 01/10/2015 kl. 17.03 skrev Rodney Jan Mandap <[email protected]>:
> 
> Hello guys, I'm 100% newbie in RoR. I have a question, how can I generate 
> report in RoR like crystal report?
> 
> -- 
> 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/9ff5a893-0b2f-4ce9-9c4e-98f7fd8fc02a%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> 
> -- 
> Denne besked er blevet skannet af 
> ALCO Stopspam, og menes at være fri for vira og spam. 
> Klik her for at rapportere denne besked som spam.

-- 
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/0551497B-2B96-404C-A2B5-7932236BBF35%40diechmann.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to