very beginner question. I am using Rails 3's query interface as shown:
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 is returning an ActiveRecord::Relation object, where in reality I want the User object that relates to the query. How do I turn this into a User object?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With