我有這樣的代碼:Rails的活動記錄對象會導致錯誤,當我嘗試訪問任何屬性
@notifications = Notification.find_all_by_user_id(@user.id, :order=>'deliver_by DESC', :conditions=>"deliver_by >= '#{Date.today.to_s(:db)}'")
logger.info @upcoming_reminders[0].inspect
logger.info @upcoming_reminders[0].class
logger.info @upcoming_reminders[0].id
logger.info "--------------------------"
記錄的結果是
#<TwitterNotification id: 1, user_id: 3, message: "Testing", deliver_by: "2009-10-30 16:00:00", created_at: "2009-10-13 12:00:45", updated_at: "2009-10-28 20:01:03", processed_at: "2009-10-13 20:00:06", type: "TwitterNotification">
TwitterNotification
ArgumentError (wrong number of arguments (1 for 0)):
app/controllers/reminders_controller.rb:57:in `get_reminders'
正如你所看到的,我得到一個參數錯誤時試圖訪問該ID。當我嘗試訪問任何屬性時,實際發生這種情況。這可能是一個盯着電腦太長的情況,但我一直無法弄清楚。有任何想法嗎?請注意,TwitterNotification是使用單表繼承實現的通知的子類。
謝謝!
UPDATE
我做了一點點的進步,這工作得很好:
logger.info @upcoming_reminders[0][:id]
所以訪問活動記錄對象的屬性與符號工作正常,但點表示沒有。任何想法爲什麼?
@upcoming_reminders數組定義在哪裏? – EmFi 2009-10-30 21:43:02