Skip to content

Instantly share code, notes, and snippets.

View aristotelesbr's full-sized avatar
🏠
Working from home

Aristóteles Coutinho aristotelesbr

🏠
Working from home
View GitHub Profile
development:
adapter: mysql2
encoding: utf8
reconnect: false
database: Ponto
pool: 5
username: root
password: root
socket: /var/run/mysqld/mysqld.sock
test:
@aristotelesbr
aristotelesbr / gist:dbcf7d554a7995a7d997
Last active August 29, 2015 14:13
O que esta faltando?
class Venda < ActiveRecord::Base
has_and_belongs_to_many :users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :vendas
end
class UsersVendas < ActiveRecord::Base
end
@aristotelesbr
aristotelesbr / gist:ccaa9490c079af9437c3
Created January 16, 2015 19:50
O relacionamento Associação has_many :through esta correto nesta situação?
class User < ActiveRecord::Base
has_many :sales
has_many :products, :through => :sales
end
class Sale < ActiveRecord::Base
belongs_to :product
belongs_to :user
end
@aristotelesbr
aristotelesbr / gist:aaf1a272be442b8bcd6e
Created January 26, 2015 18:43
Criar uma nova venda somente se o valor em Produtos for maior que 0.
def create
@sale = Sale.new(sale_params)
if @sale.amount <= @product.amount
redirect_to root_path, :notice => "Quantidade indisponível"
else
@sale.save
respond_with(@sale)
end
end
@aristotelesbr
aristotelesbr / dvd.rb
Created February 10, 2015 03:07
cap. 7 pg 102 - Compartilhando Comportamentos: Herança, Módulos e Mixins.
class DVD < Midia
def initialize(titulo, valor, categoria)
@titulo = titulo
@valor = valor
@categoria = categoria
end
def to_s
%Q{ Título: #{@titulo}, Valor: #{@valor} }
end
end
require "fileutils"
class Revista
def self.find(id)
raise DocumentNotFound,
"Arquivo db/revistas/#{id} não encontrado.", caller
unless File.exists?("db/revistas/#{id}.yml")
YAML.load File.open("db/revistas/#{id}.yml", "r")
encontrado
end
end
require 'fileutils'
module ActiveFile
def save
@new_record = false
File.open("db/revistas/#{@id}.yml", "w") do |file|
file.puts serialize
end
end
= simple_form_for @product, html: { multipart: true } do |f|
- if @product.errors.any?
#errors
%h2
= pluralize(@product.errors.count, "error")
prevented this product from saving
%ul
- @product.errors.full_messages.each do |msg|
%li= msg
class Meta
def initialize(meta = {})
@meta = meta
end
def atingir_meta(meta)
return meta
end
def dobrar_meta(meta)
meta*2
end
Vagrant.configure(2) do |config|
config.vm.box = "fnando/hellobits-trusty32"
end