Skip to content

Instantly share code, notes, and snippets.

View brunoandradd's full-sized avatar

Bruno Andrade brunoandradd

View GitHub Profile
@brunoandradd
brunoandradd / migratepaperclip.rb
Created December 17, 2011 21:43
papercliper migrate example
class AddAvatarColumnsToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.has_attached_file :avatar
end
end
def self.down
drop_attached_file :users, :avatar
end
module DateTimeComposer
module ActiveRecordExtensions
module ClassMethods
def compound_datetime(*attrs)
define_compounds(attrs)
end
def define_compounds(attrs)
attrs.each do |attr|
class_eval <<-METHODS
@brunoandradd
brunoandradd / gist:3777274
Created September 24, 2012 17:50
Config nginx com php/ruby
worker_processes 3;
events {
worker_connections 1024;
}
http {
passenger_root /usr/local/lib/ruby/gems/1.8/gems/passenger-3.0.7;
passenger_ruby /usr/local/bin/ruby;
#pseudo codigo em topic_manager
def add_post(forem_user,post_attributes)
@post = @topic.posts.build(post_attributes)
@post.user = forem_user
@post.save
end
class PostsController < Forem::ApplicationController
@brunoandradd
brunoandradd / consular.rb
Created February 12, 2013 13:39
Consular example
# COMMENT OF SCRIPT HERE
# you can make as many tabs as you wish...
# tab names are actually arbitrary at this point too.
before do
run "cd ~/griffti/apps/multiconstrutora"
end
tab "rails server" do
@brunoandradd
brunoandradd / report_dsl.rb
Created November 17, 2013 18:54
Dsl para relatórios
#definição
module RepositorioRelatorios
extend self
def adicionar(relatorio)
@relatorios ||= []
@relatorios.push relatorio
end
class ResumosFinanceirosController < ApplicationController
before_filter do
@consulta_previa = ConsultaPrevia.find(params[:consulta_previa_id])
end
def edit
@investimentos = Investimentos.new(@consulta_previa.empreendimento)
@fontes = Fontes.new(@consulta_previa.empreendimento)
@resumo_financeiro = @consulta_previa.empreendimento.resumo_financeiro
class PacientesController < ApplicationController
before_action :protected_show, only: [:show]
def show
@paciente = Paciente.find(params[:id])
end
private
def protected_show
unless clinica_logada.pacientes.where(id: params[:id]).any?
# controller metodo index:
def index
@consultorios = BuscadorConsultorio.new(params).filtrar
end
# novo objeto de busca
class BuscadorConsultorio
def new(opcoes_busca, buscado_padrao = Setor::Consultorio)
@brunoandradd
brunoandradd / Serialize.rb
Created June 19, 2014 20:15
Serialize.rb
class CustomerSerializer < ActiveModel::Serializer
attributes :id, :name, :email
end
class SchedulingSerializer < ActiveModel::Serializer
attributes :id, :beauty_salon_id, :schedule_id, :customer_id,
:date_scheduling, :hour, :beauty_salon
has_many :services