start new:
tmux
start new with session name:
tmux new -s myname
By default, Rails applications build URLs based on the primary key -- the id
column from the database. Imagine we have a Person
model and associated controller. We have a person record for Bob Martin
that has id
number 6
. The URL for his show page would be:
/people/6
But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6
here, is called the "slug". Let's look at a few ways to implement better slugs.
ruby '2.7.1' | |
gem 'rails', github: 'rails/rails' | |
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data | |
# Action Text | |
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra' | |
gem 'okra', github: 'basecamp/okra' | |
# Drivers |
import React from "react"; | |
import { render } from "react-dom"; | |
const ParentComponent = React.createClass({ | |
getDefaultProps: function() { | |
console.log("ParentComponent - getDefaultProps"); | |
}, | |
getInitialState: function() { | |
console.log("ParentComponent - getInitialState"); | |
return { text: "" }; |
# encoding: UTF-8 | |
# pt-BR translations for Devise | |
pt-BR: | |
devise: | |
confirmations: | |
confirmed: "Sua conta foi confirmada com sucesso. Você está logado." | |
send_instructions: "Dentro de minutos, você receberá um e-mail com instruções para a confirmação da sua conta." | |
send_paranoid_instructions: "Se o seu endereço de e-mail estiver cadastrado, você receberá uma mensagem com instruções para confirmação da sua conta." | |
failure: | |
already_authenticated: "Você já está logado." |
/* eslint-disable */ | |
// For more infos, see: https://github.com/jquense/yup/blob/master/src/locale.js | |
import { setLocale } from 'yup' | |
const translation = { | |
mixed: { | |
default: '${path} é inválido', | |
required: '${path} é um campo obrigatório', | |
oneOf: '${path} deve ser um dos seguintes valores: ${values}', | |
notOneOf: '${path} não pode ser um dos seguintes valores: ${values}', |
var http = require('http'), | |
httpProxy = require('http-proxy'); | |
httpProxy.createServer(function (req, res, proxy) { | |
if(req.headers.host == 'sadjow.com') { | |
proxy.proxyRequest(req, res, { | |
host: 'sadjow.com', | |
port: 3000 | |
}); |
In researching topics for RailsCasts I often read code in Rails and other gems. This is a great exercise to do. Not only will you pick up some coding tips, but it can help you better understand what makes code readable.
A common practice to organize code in gems is to divide it into modules. When this is done extensively I find it becomes very difficult to read. Before I explain further, a quick detour on instance_eval
.
You can find instance_eval
used in many DSLs: from routes to state machines. Here's an example from Thinking Sphinx.
class Article < ActiveRecord::Base
# encoding: utf-8 | |
# Be sure to restart your server when you modify this file. | |
# Add new inflection rules using the following format | |
# (all these examples are active by default): | |
# ActiveSupport::Inflector.inflections do |inflect| | |
# inflect.plural /^(ox)$/i, '\1en' | |
# inflect.singular /^(ox)en/i, '\1' | |
# inflect.irregular 'person', 'people' | |
# inflect.uncountable %w( fish sheep ) |