Enabling ActiveRecord :: Model Relationship

very newbie question. I am using the Rails 3 query interface as shown below:

class User < ActiveRecord::Base def self.authenticate if Rails.env = 'development' self.where('username = ?', 'development_user') else self.where('username = ?', request.env['REMOTE_USER']) end end end 

This returns an ActiveRecord :: Relation object, where in fact I want the User object to be associated with the request. How to turn this into a User object?

+7
source share
1 answer

You need to β€œcommit” the query with all , first or find .

 def self.authenticate user = Rails.env.development? ? "development_user" : request.env['REMOTE_USER'] self.where('username = ?', user).first end 
+12
source

All Articles