Skip to content

Instantly share code, notes, and snippets.

module LocationsHelper
def self.detailed_information(location)
detailed_information =[ ["Accepts credit cards?", location.accepts_credit_cards] ]
unless location.smoking_policy.nil?
detailed_information << [ "Smoking Policy", location.smoking_policy]
end
unless location.center.nil?
detailed_information << ["Center" , location.center.name, center_path(location.center.id)]
end
module ActiveRecord
class Base
def self.random
if (c = count) != 0
find(:first, :offset =>rand(c))
end
end
end
end
module SessionsHelper
def deny_access
#store_location
notice = current_user.nil?? "Please sign in to access this page" : "You must sign in as an admin to access this page"
#flash[:error] = notice
logger.debug "here"
logger.debug notice
#flash[:notice] = notice
logger.debug flash[:notice]
def self.deflate(string)
zstream = Zlib::Deflate.new
buf = zstream.deflate(string)
zstream.finish
zstream.close
buf
end
include LocationsHelper
include SessionsHelper
class LocationsController < ApplicationController
before_filter :admin_user, :only => [:new, :create, :edit, :destroy]
def new
end
def create
class AuthsController < ApplicationController
include AuthsHelper
def helloauth
flash[:error] = session[:hello]
redirect_to root_path
end
end
@zxiest
zxiest / Warning redundant nested repeat operator
Created April 14, 2011 08:20
Warning redundant nested repeat operator
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/strexp.rb:4
1: warning: redundant nested repeat operator
c:/Ruby192/lib/ruby/gems/1.9.1/gems/actionpack-3.0.5/lib/action_dispatch/routing
/route.rb:25: warning: redundant nested repeat operator
c:/Ruby192/lib/ruby/gems/1.9.1/gems/rack-mount-0.6.13/lib/rack/mount/route.rb:46
: warning: redundant nested repeat operator
@zxiest
zxiest / ActiveRecord fill
Created April 14, 2011 11:31
ActiveRecord fill
module ActiveRecord
class Base
def fill(hash, ignore =[])
b = self.getBinding
hash.each do |k,v|
if !ignore.include?(k)
#send(k + "=", v)
eval("#{k} = #{v}", b)
end
@zxiest
zxiest / OperationInterval
Created April 14, 2011 11:42
OperationInterval
class OperationInterval < ActiveRecord::Base
include OperationIntervalsHelper
before_save :fix_values
before_update :fix_values
AMPM = [ "am", "pm" ]
HOURS = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" ]
MINUTES = ["00", "15", "30", "45"]
DAYS = ["M", "T", "W", "Th", "F", "S", "Su"]
irb(main):010:0> x
=> {"start_day"=>"M", "end_day"=>"F", "f_start_hour"=>"8", "start_minute"=>"00",
"start_ampm"=>"am", "f_end_hour"=>"7", "end_minute"=>"00", "end_ampm"=>"pm", "o
ld_record"=>"18"}
irb(main):011:0> temp = OperationInterval.find(18)
=> #<OperationInterval id: 18, days: nil, start_hour: nil, start_minute: 0, end_
hour: nil, end_minute: 0, closed: nil, created_at: "2011-04-14 09:28:21", update
d_at: "2011-04-14 09:28:21">
irb(main):012:0> temp.attributes= x
=> {"start_day"=>"M", "end_day"=>"F", "f_start_hour"=>"8", "start_minute"=>"00",