控制器引用模型时就说方法不存在,怪的是在 AController 正常,但在 BController 就说
ActionView::TemplateError (undefined method idno' for nil:NilClass)
并且在AView <%= @current_user.idno %>正常。
但在BView <%= @current_user.idno %> 时也报同样错:
ActionView::TemplateError (undefined method
idno' for nil:NilClass)
代码如下:
ApplicationController < ActionController::Base
@current_user = User.find_by_id(params[:user_id])
......
end
AController < ApplicationController
@contas = Conta.find(:first,:conditions => ["idno=?", @current_user.idno])
..........
end
BController < ApplicationController
@contas = Conta.find(:first,:conditions => ["idno=?", @current_user.idno])
..........
end