2012-07-24 26 views
0

我已生成User模型以及另外兩個名爲UpdateRound的伴隨模型。 User類響應循環和控制檯中的更新,但不是在瀏覽器中調用它時。Rails用戶類對方法沒有響應,給出了未定義的方法錯誤

在控制檯

:001 > user = User.first 
:002 > user.updates 
Update Load (0.2ms) SELECT "updates".* FROM "updates" WHERE "updates"."user_id" = 1 
=> [] //expected since there are no updates in the database but it responds 

/用戶/ 1 /更新錯誤

undefined method 'updates' for #<Class:0x98afa1c> 

User.rb

class User < ActiveRecord::Base 

    attr_accessible :admin, :name, :provider :uid 
    has_many :rounds 
    has_many :updates 

end 

Update.rb

class Updates < ActiveRecord::Base 

    attr_accessible :user_id :recpcount 
    belongs_to :user 
end 

Updates_controller.rb

class UpdatesController < ApplicationController 

    def index 
    @hist = User.updates.find(params[id]) 
    end 
end 

我敢肯定,我亂七八糟的東西簡單的某處。任何人都能帶領我走向正確的方向嗎?謝謝!

回答

1

在控制檯你在用戶實例調用updates,但在控制你調用它本身的用戶類。

很可能,你想:

@hist = User.find(params[:id]).updates 
+0

謝謝,正是我需要的! – SomberClock 2012-07-25 23:02:11

0
@hist = User.updates.find(params[id]) 

這是你的問題。 User該類沒有updates,實例。你可能想:

@user = User.find(params[id]) 
@hist = @user.updates 
+0

感謝您的幫助! – SomberClock 2012-07-25 23:01:01

相關問題