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
#!/bin/bash | |
DBNAME=<database_name> | |
DBUSER=<database_user> | |
DBHOST=<host> | |
DUMP_FILE=$1 | |
if [[ $DUMP_FILE == "" ]]; then | |
echo "[ERROR] Arquivo de dump não especificado" |
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
# instalando postgres e dependências | |
sudo apt-get install postgresql postgresql-contrib postgresql-server-dev-9.5 | |
# acessando o postgres | |
sudo su - postgres | |
psql | |
# alterando o encoding que vem por padrão | |
update pg_database set encoding = 6, datcollate = 'pt_BR.UTF-8', datctype = 'pt_BR.UTF-8' where datname = 'postgres'; | |
update pg_database set encoding = 6, datcollate = 'pt_BR.UTF-8', datctype = 'pt_BR.UTF-8' where datname = 'template0'; |
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 DateValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
valid = value.to_date rescue false | |
record.errors[attribute] << ( | |
options[:message] || "invalid date" | |
) unless valid | |
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
# models de exemplo | |
rails g model product name:string description:text price:decimal | |
rails g model location lease_at:date return_at:date status:boolean | |
# application.rb | |
config.autoload_paths += %W["#{config.root}/app/validators/"] | |
# date_validator.rb | |
class DateValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) |
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
default: &default | |
adapter: postgresql | |
encoding: utf8 | |
collate: pt_BR.UTF-8 | |
ctype: pt_BR.UTF-8 | |
host: host | |
username: username | |
timeout: 5000 | |
development: |
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
Verbo Padrão URL Ação | |
GET /model(.:format) model#index | |
GET /model/new(.:format) model#new | |
POST /model(.:format) model#create | |
GET /model/:id/edit(.:format) model#edit | |
PATCH /model/:id(.:format) model#update | |
PUT /model/:id(.:format) model#update |
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
# tipagem forte | |
a = 2 | |
b = '4' | |
a * b | |
#=> TypeError: String can't be coerced into Fixnum | |
# tipagem dinamica | |
idade = 25 | |
idade = '25' |
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
# métodos | |
def some_method() | |
end | |
# convenção para métodos booleanos | |
def empty?() | |
end | |
# convenção para métodos destrutivos | |
def sort!() |
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 Access | |
def initialize(a, b, c) | |
@a = a | |
@b = b | |
@c = c | |
end | |
# acessível de qualquer lugar | |
def a | |
@a |
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
# módulo | |
module SomeModule | |
# pode ser chamado de qualquer lugar | |
def SomeModule.handle | |
puts 'some method' | |
end | |
# chamado pelas classes que incluem o módulo | |
def handle | |
puts 'other method' |