$ brew install nginx
$ vim /usr/local/etc/nginx/nginx.conf
class Driver | |
attr_reader :name | |
def initialize(name) | |
@name = name | |
end | |
end | |
class Car | |
def initialize(model:, driver:) |
# frozen_string_literal: true | |
# Runs with | |
# ruby 3.3 | |
# webmock 3.23 | |
# minitest 5.24.1 | |
require 'uri' | |
require 'net/http' | |
require 'json' | |
require 'webmock/minitest' |
require 'net/ldap' | |
module Ldap | |
LDAP_SERVER_IP = 'buzon.uach.mx'.freeze | |
#LDAP_USERNAME = 'ldap_username' | |
#LDAP_PASSWORD = 'ldap_password' | |
#Obtiene el nombre mediante su cuenta de usuario |
#the do´s | |
2.hours.ago # => Thu, 27 Aug 2015 14:39:36 AFT +04:30 | |
1.day.from_now # => Fri, 28 Aug 2015 16:39:36 AFT +04:30 | |
Time.zone.parse("2015-08-27T12:09:36Z") # => Thu, 27 Aug 2015 16:39:36 AFT +04:30 | |
Time.current # => Thu, 27 Aug 2015 16:39:36 AFT +04:30 | |
Time.current.utc.iso8601 # When supliyng an API ("2015-08-27T12:09:36Z") | |
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z").in_time_zone # If you can’t use Time.zone.parse (Thu, 27 Aug 2015 16:39:36 AFT +04:30) | |
Date.current # If you really can’t have a Time or DateTime for some reason (Thu, 27 Aug 2015) | |
Date.current.in_time_zone # If you have a date and want to make the best out of it (Thu, 27 Aug 2015 00:00:00 AFT +04:30) | |
#the don´ts |
db:create #Creates the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases. | |
db:create:all #Creates the database for all environments. | |
db:drop #Drops the database for the current RAILS_ENV environment. If RAILS_ENV is not specified it defaults to the development and test databases. | |
db:drop:all #Drops the database for all environments. | |
db:migrate #Runs migrations for the current environment that have not run yet. By default it will run migrations only in the development environment. | |
db:migrate:redo #Runs db:migrate:down and db:migrate:up or db:migrate:rollback and db:migrate:up depending on the specified migration. I usually run this after creating and running a new migration to ensure the migration is reversable. | |
db:migrate:up #Runs the up for the given migration VERSION. |
As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.
All the complexity is handled by ActiveRecord::Transactions
. Any model class or instance has a method named .transaction
. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.
HTTP status code symbols for Rails | |
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings. | |
Status Code Symbol | |
1xx Informational | |
100 :continue | |
101 :switching_protocols | |
102 :processing |
#Date Formatting I | |
'%Y' #Year with century (e.g. 2015, 1995, etc) | |
'%m' #Month of the year, zero-padded (01..12) | |
'%B' #The full month name (e.g. January) | |
'%b' #The abbreviated month name (e.g. Jan) | |
'%d' #Day of the month, zero-padded (01..31) | |
'%j' #Day of the year (001..366) | |