Skip to content

Instantly share code, notes, and snippets.

@waynephipps
Created July 25, 2014 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save waynephipps/d6e253caad3d5aa2d518 to your computer and use it in GitHub Desktop.
Save waynephipps/d6e253caad3d5aa2d518 to your computer and use it in GitHub Desktop.
Accessing ActiveRecord fields
class AppUser < ActiveRecord::Base
self.table_name = "AppUsers"
self.primary_key = 'UserID'
def self.authenticate(user_id, password)
if user = AppUser.where(UserID: user_id, Password: password)
unless user.nil? || user.empty?
return user
end
end
return nil
end
end
def login_attempt
authorized_user = AppUser.authenticate(params[:user_id],params[:user_password])
@user = authorized_user.column_names
if authorized_user
redirect_to(:action => 'main')
else
flash[:notice] = "Invalid Username or Password"
flash[:color]= "invalid"
render "login"
end
end
AppUser.authenticate('ADMIN', '')
AppUser Load (0.9ms) EXEC sp_executesql N'SELECT TOP (1) [AppUsers].* FROM [AppUsers] WHERE [AppUsers].[UserID] = N''ADMIN'' AND [AppUsers].[Password] = N'''' ORDER BY [AppUsers].[UserID] ASC'
=> #<AppUser UserID: "ADMIN", UserName: "Administrator", MenuGroup: "SYS_ADMIN", Password: "", DefaultStoreID: "1", FullRights: true, LastChanged: "2013-10-23 17:59:52", ChangedBy: "ADMIN", Email: "", Phone: "", Deleted: false, CashierID: "", HideCostPrice: false, WebLogin: false, CustomerID: "", DepID: "", NetworkID: "">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment