Skip to content

Instantly share code, notes, and snippets.

View bogdan's full-sized avatar

Bogdan Gusiev bogdan

View GitHub Profile
require "resque"
if (Rails.env.development? || Rails.env.test?) && !ENV['RESQUE']
Resque.class_eval do
def enqueue(clazz, *arguments)
clazz.perform(*arguments)
end
end
end
def update
old_email = @partner.email
@partner.attributes = params[:partner]
if @partner.partner_logo.save and @partner.save
#fire new password if email changed
unless @partner.email == old_email
@partner.change_password
flash[:notice] = I18n.translate "flashes.password_changed"
end
class CompanyObserver < ActiveRecord::Observer
observe Company
def after_create(company)
unless company.current_issue
Issue.create!(
:title => "Создана компания #{company.title}",
:source => company
)
end
class CustomPage < ActiveRecord::Base
validates_presence_of :title, :message => "заполните заголовок"
validates_presence_of :body, :message => "заполните содержание"
belongs_to :company
has_friendly_id :title, :use_slug => true
end
callbacks.each do |callback|
class_eval <<-"end_eval"
def self.#{callback}(*methods, &block) # def self.before_save(*methods, &block)
callbacks = CallbackChain.build(:#{callback}, *methods, &block) # callbacks = CallbackChain.build(:before_save, *methods, &block)
@#{callback}_callbacks ||= CallbackChain.new # @before_save_callbacks ||= CallbackChain.new
@#{callback}_callbacks.concat callbacks # @before_save_callbacks.concat callbacks
end # end
#
def self.#{callback}_callback_chain # def self.before_save_callback_chain
@#{callback}_callbacks ||= CallbackChain.new # @before_save_callbacks ||= CallbackChain.new
$('html').ajaxSuccess(function(event,request,options) {
var data = null;
try {
data = $.parseJSON(request.responseText);
} catch(e) {
// well... this is hacky and we're parsing all incoming ajax responses. i'd really like to do this in a nicer way
}
if ((data!==null) && (data.flash!==null)) {
$.each(data.flash, function(k,v) {
$.flash(v, {type: k});
elsif options.include?(:json)
json = options[:json]
json = ActiveSupport::JSON.encode(json) unless json.is_a?(String)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
response.content_type ||= Mime::JSON
render_for_text(json, options[:status])
def render(options = nil, *args)
if options.is_a?(Hash)
if json = options[:json]
if json.is_a?(Hash)
json[:flash] = flash
end
end
end
super(options, *args)
end
app/controllers/gmail_controller.rb|28| rescue OAuth::Unauthorized => e
app/models/matching_profile.rb|133| rescue ExpressionError => e
app/utils/distribution_report.rb|28| rescue TypeError
config/boot.rb|64| rescue Gem::LoadError => load_error
config/boot.rb|71| Gem::RubyGemsVersion rescue nil
config/boot.rb|92| rescue LoadError
config/preinitializer.rb|12| rescue Bundler::GemNotFound
db/seeds.rb|167| rescue => e
lib/expression.rb|9| rescue ExpressionError => e
lib/expression.rb|52| rescue => e
grammar BooleanGrammar
rule andable
orable '&' andable {
def value(&block)
orable.value(&block) && andable.value(&block)
end
}
/ orable
end