I have generated a User model along with 2 other accompanying models called Update and Round. The User class responds to rounds and updates in the console but not when I call for it in the browser.
In console
: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
/user/1/update error
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
Im sure I messed something simple up somewhere. Can anyone lead me in the right direction? Thanks!
In the console you’re calling
updateson a User instance, but in the controller you’re calling it on the User class itself.You may instead want: