我认为@user
是一个实例变量,应该在我访问 之后设置localhost://users/1
,现在如果我导航到localhost://users/new
,为什么@user
是 nil?
class UsersController < ApplicationController
def new
# normally you would create a new model and assign it to the instance variable,
# but if I comment it out, why is it nil instead of keeping the value from show action?
# @user = User.new
end
def show
@user = User.find(params[:id])
end
end