已解决:当没有人登录并且没有当前用户时,问题是在控制器中调用 current_user,它会引发错误,感谢您的努力/时间。
我希望人们能够在我的应用程序中查看个人资料页面,无论他们是否在我的网站上拥有帐户。目前我收到错误:
SQL:
Started GET "/users/1" for 127.0.0.1 at 2013-02-05 05:08:50 -0500
Processing by UsersController#show as HTML
Parameters: {"id"=>"1"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT 1 [["id", "1"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."remember_token" IS NULL LIMIT 1
NoMethodError (undefined method `microposts' for nil:NilClass):
app/controllers/users_controller.rb:34:in `show'
我认为它试图定义一个记住令牌,而当某人实际上没有登录时不应该有一个。
用户控制器:
def show
@user = User.find_by_id(params[:id])
@microposts = @user.microposts.paginate(page: params[:page])
@micropost = current_user.microposts.build
End