我在我的应用程序中遇到了一个错误,以解释上下文:一个用户有几辆车,每辆车都可以进行加油,因此我的 TankingLogsController 如下
class TankingLogsController < ApplicationController
def new
@user = User.find(params[:user_id])
@car = @user.cars.find(params[:car_id])
@tankinglog = @cars.tanking_logs.build
end
end
这是我的 routes.rb 文件
Estaciones::Application.routes.draw do
root :to => "static_pages#home"
match '/contact', :to=>'static_pages#contact'
match '/about', :to=>'static_pages#about'
devise_for :users
resources :users do
resources :cars do
resources :tanking_logs
end
end
...
我遇到了这个错误:
NoMethodError in TankingLogsController#new
undefined method `tanking_logs' for nil:NilClass
Application Trace | Framework Trace | Full Trace
app/controllers/tanking_logs_controller.rb:5:in `new'
为什么我的应用程序失败?