In my app I have a page that posts the statuses of users I follow. I'm new to rails and this error is killing me. I can give anything else if its needed
pages_controller.rb
def home
if signed_in?
@hub_items = current_user.hub.paginate(page: params[:page])
end
end
user.rb
def hub
Timeline.from_users_followed_by(self)
end
timeline.rb
def self.from_users_followed_by(user)
followed_user_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
where("user_id IN (#{followed_user_ids}) OR user_id = :user_id",
user_id: user.id)
end
And this is the error trace.
Started GET "/" for 127.0.0.1 at 2014-08-24 14:11:28 -0700 Processing by PagesController#home as HTML User Load (3.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 4]] Completed 500 Internal Server Error in 257ms
NoMethodError (undefined method `where' for Timeline:Class):
app/models/timeline.rb:47:in `from_users_followed_by' app/models/user.rb:24:in `hub' app/controllers/pages_controller.rb:5:in `home'
Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.1.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.0ms) Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.1.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.0ms) Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.1.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (5.0ms) Rendered C:/Ruby200/lib/ruby/gems/2.0.0/gems/actionpack-4.1.2/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (646.0ms)
Timeline
class in not inheriting fromActiveRecord::Base
, so the.where
method is not present. Guess you're wanting to do aPost.where(...)
. – Thomas Klemmwhere
on your model is becuase its not inheriting fromActiveRecord::Base
– Pramod Solanky