0
我在我的應用程序運行到一個錯誤,解釋的背景:一個用戶有好幾輛車,每輛車可以使一個,因此我的坦克是TankingLogsController以下NoMethodError在NameController#新
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'
爲什麼我的應用程序失敗?
是的,我看到了,謝謝我不知道發生了什麼事 – Asantoya17 2012-07-27 15:11:50