Skip to content

Customization for different Controllers Actions

Shiva Bhusal edited this page Apr 10, 2016 · 1 revision

Lets say you have to generate two different reports with only the list/table being common and have different header and footer. In other words you want to have your own layout where you can yield the view given by QueryReport. Also from different controllers or Actions

  • You need to say Query Report that you are going to use your custom view so please don't bother rendering.
  • You need to manually specify the view you want to render using render 'templatename' or let Rails render the default template.
    • Better would be using the default template; say, if you have reports#sales action then your template would be views/reports/sales.slim or .erb
def sales
  reporter(events, custom_view: true) do
  ...
  end
end

custom_view: true tells Query Report not to render its default view. For more info see this

and in views/reports/sales.slim

= render partial: 'header', locals: {report: @report}

div.sales-analytics
  = render_query_report(@report)

= render partial: 'footer', locals: {report: @report}
Clone this wiki locally