This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StoredProcedureService | |
def self.instance | |
@instance ||= StoredProcedureService.new | |
end | |
def execute(name, *args) | |
results = [] | |
begin | |
connection.execute("CALL #{name}(#{args.join(',')})").each(as: :hash, symbolize_keys: true) do |row| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH RECURSIVE tiers (a, b, c) AS MATERIALIZED ( | |
SELECT | |
* | |
FROM | |
"tiers" | |
WHERE | |
NOT ( | |
EXISTS ( | |
SELECT | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ArelHelpers | |
extend self | |
def self.included(base) | |
base.extend self | |
end | |
def asterisk(arel_table_or_model) | |
arel_table, columns = case arel_table_or_model | |
when Arel::Table |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ok, so I'm trying to replace a ' character with \' in a ruby string. I have working code, but it was | |
*way* too painful getting there for my taste. | |
Take a look: | |
ree-1.8.7-2010.02 :001 > single_quote = "\'" | |
=> "'" | |
ree-1.8.7-2010.02 :003 > single_quote.gsub(/'/, "\\\'") | |
=> "" | |
ree-1.8.7-2010.02 :004 > single_quote.gsub(/'/) {|c| "\\'"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
ref: https://gist.github.com/ahoward/5752290 | |
web apps nearly always end up needing a plethora of little javascript helper methods: you know, auto-complete forms, populating defaults, validations, etc. these aren't API calls properly, just little tidbits of functionality needed to make the views work. | |
there is always a question of which controller to hang these methods off of. do you make a global helper controller for all this stuff? do you hang them off the controller in question? how to do share the backend of javascript helper methods across controllers? | |
step one |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Decorator | |
@@decorators = [] | |
def decorate(method_name,*args) | |
@@decorators << [method_name.to_sym,args] | |
end | |
def method_added(method_name) | |
super | |
return if @@decorators.empty? | |
decorators = @@decorators.reverse.map{|name,args| [method(name),args]} | |
@@decorators = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pdf_generator' | |
class TasksController < ApplicationController | |
include PdfGenerator | |
def some_action | |
pdf_generator( download = true ) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See http://blog.waxman.me/extending-your-models-in-rails-3 for original post | |
module Extensions | |
module Popular | |
module ClassMethods | |
def most_popular(limit=10) | |
order('points desc').limit(limit).all | |
end | |
end | |
def popularity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
ActiveAdmin.register Gallery do | |
menu :label => 'Galerías' | |
# => Índice | |
index do | |
column :name | |
column :description | |
column :date | |
default_actions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActiveAdmin.register Product do | |
permit_params :name, :category_id, :description, :text, :slug, :in_slider, :tag_ids => [] | |
filter :category | |
filter :base_tags | |
filter :name | |
filter :text | |
filter :created_at | |
filter :updated_at |