0
我在玩Ruby,試圖實現像app這樣的基本社交網絡。current_user和created_at導致TypeError
我有兩個視圖,我想顯示狀態更新,用戶#顯示和主頁(您將添加狀態更新,也可視化您自己)。
在家中,它返回Home#索引中的錯誤TypeError,無法將nil轉換爲精確數字。但是,如果我硬編碼@user作爲User.find(1)工作正常,它似乎衝突只是@user = current_user(我正在使用設計)。
家居控制器:
class HomeController < ApplicationController
def index
@user = current_user
@new_status_update = current_user.status_updates.build if user_signed_in?
@status_updates = @user.status_updates
end
end
users控制器:
class UsersController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :only => :index
def show
@user = User.find(params[:id])
@status_updates = @user.status_updates
end
end
循環是在意見相同
我現在注意到它只發生在調用time_ago_in_words(status_update.created_at) – Dave