Log In or Sign Up

Quick access to users

Tags:
ActiveRecord, utility methods
Posted by:
Michael Bleigh 8 months ago

This quick little method makes it really easy to pull up a specific user in your app, just call User[:login] and you have them! I use it primarily in script/console.

class User < ActiveRecord::Base
  def User.[](key)
    if key.is_a?(Integer)
      User.find_by_id(key)
    else
      User.find_by_login(key.to_s)
    end
  end
end

Comments

No one has commented on this yet.

You must be logged in to post a comment.