I’m starting a new Rails 3.2.6 application. My nested route is failing when I attempt to view the new nested form. I’ll first show the error, then all of the code involved.
URL attempting to access: http://localhost:3000/reports/1/expenses/new
No route matches {:action=>"show", :controller=>"expenses", :report_id=>#<Report id: 1, name: "Test Report", created_at: "2012-06-07 21:58:37", updated_at: "2012-06-07 21:58:37">}
routes.rb
resources :reports do
resources :expenses
end
expenses_controller.rb
def new
@report = Report.find(params[:report_id])
@expense = @report.expenses.new
end
views/expenses/new.html.haml
%h1 New Expense
= render 'form'
views/expenses/_form.html.haml
= form_for [@report, @expense] do |f|
This is the link I’m attempting to click:
= link_to 'New Expense', new_report_expense_path(@report)
I can’t figure out why it’s trying to access the show action when I’m explicitly calling the new action.
Rake Routes
report_expenses GET /reports/:report_id/expenses(.:format) expenses#index
POST /reports/:report_id/expenses(.:format) expenses#create
new_report_expense GET /reports/:report_id/expenses/new(.:format) expenses#new
edit_report_expense GET /reports/:report_id/expenses/:id/edit(.:format) expenses#edit
report_expense GET /reports/:report_id/expenses/:id(.:format) expenses#show
PUT /reports/:report_id/expenses/:id(.:format) expenses#update
DELETE /reports/:report_id/expenses/:id(.:format) expenses#destroy
reports GET /reports(.:format) reports#index
POST /reports(.:format) reports#create
new_report GET /reports/new(.:format) reports#new
edit_report GET /reports/:id/edit(.:format) reports#edit
report GET /reports/:id(.:format) reports#show
PUT /reports/:id(.:format) reports#update
DELETE /reports/:id(.:format) reports#destroy
root / reports#index
UPDATE
Link to GitHub repo: https://github.com/ardavis/expense_report
The error is in the views/expences/_form.html.haml, last line
You probably meant