I gave a controller called reports in my Rails 3 application. The index section of the controller looks like this:
def index
#@reports = Report.all
@clinical_income_by_month = Clinical.income_by_month
@clinical_income_by_employee = Clinical.income_by_employee
@clinical_income_by_vet = Clinical.income_by_vet
@consult_consult_times = Consult.consult_times
@clinical_healthplan_high_spenders = Clinical.healthplan_high_spenders
respond_to do |format|
format.html # index.html.erb
format.json { render json: @reports }
end
end
The index.html.erb code looks like this:
<h6><b>Financial Reports</b></h6>
<dl class="vertical">
<dd><a href="/income_by_month">Income by Month</a></dd>
<dd><a href="/income_by_employee">Income by Employee</a></dd>
<dd><a href="/income_by_vet">Income by Vet</a></dd>
</dl>
I have split the reports which were originally all in index.html.erb under jQuery tabs into their own pages.
What is the best way to make the links to the individual reports load? Currenly if I visit the links or manually enter http://0.0.0.0:3000/reports/income_by_month.html I get an unknown page error.
Any pointers would be appreciated!
One of your first steps is to add methods in your controller for each of the different reports. These go in your
config/routes.rbfile:The result of this is to give you paths to your reports of:
Then, in your erb the best way to refer to the reports using
_pathvariables like so:A good place for you to start is this primer called “Ruby on Rails Guides: Rails Routing from the Outside In”