【发布时间】:2012-06-16 04:32:48
【问题描述】:
我正在启动一个新的 Rails 3.2.6 应用程序。当我尝试查看新的嵌套表单时,我的嵌套路由失败。我将首先显示错误,然后显示所有涉及的代码。
试图访问的 URL: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
观看次数/费用/new.html.haml
%h1 New Expense
= render 'form'
观看次数/费用/_form.html.haml
= form_for [@report, @expense] do |f|
这是我试图点击的链接:
= link_to 'New Expense', new_report_expense_path(@report)
当我明确调用新操作时,我无法弄清楚为什么它会尝试访问显示操作。
耙式路线
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
更新 GitHub 仓库链接:https://github.com/ardavis/expense_report
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 routes