Skip to content

Instantly share code, notes, and snippets.

View sergii's full-sized avatar

Serhii Ponomarov sergii

View GitHub Profile

Some Rails Best Practices which are really best practices to me

Keep in mind

  1. Single Responsibity Principle (SRP).
  2. Skinny Controller, Fat Model.

Tips

  1. Start a new projet
@sergii
sergii / gist:26ed944c1e735158f6fe
Last active August 29, 2015 14:08
Simplest way to install rabbitMQ in Ubuntu
http://stackoverflow.com/questions/8808909/simple-way-to-install-rabbitmq-in-ubuntu
echo "deb http://www.rabbitmq.com/debian/ testing main" | sudo tee /etc/apt/sources.list.d/rabbitmq.list > /dev/null
sudo wget http://www.rabbitmq.com/rabbitmq-signing-key-public.asc
sudo apt-key add rabbitmq-signing-key-public.asc
sudo apt-get update
sudo apt-get install rabbitmq-server -y
sudo service rabbitmq-server start
sudo rabbitmq-plugins enable rabbitmq_management
sudo service rabbitmq-server restart

Steps in creating a basic rails app

  1. Define your model(s)
  • What tables should exist in the database?
  • What fields should each table have?
  1. Define your associations
  • What are the relationships between your tables?
  1. Generate models
  2. Create your controllers

Deploying to Heroku

This guide is for a first-time Rails developer to deploy their app to Heroku, a popular web-hosting service with strong Rails support. This guide assumes you already have a Heroku account and have installed the Heroku Toolbelt.

Create Your App and Setup Heroku with Git

  1. Make sure you've setup an SSH key for Heroku. Follow this simple guide to create an SSH key and send it to Heroku if needed: Heroku: Managing Your SSH Keys
  2. Navigate into the folder for your Rails app.

Example Application Layout File

This is an example or boilerplate layout file. Your layout file is the frame rendered around every view in your app (via the <%= yield %> erb tag at the bottom). Every Rails app has a layout file at app/views/layouts/application.html.erb.

What's Included?

This layout file includes:

These steps are for Mavericks. Mileage will vary for older versions of Mac OS X but the broad strokes still apply. Google is your friend if you hit a snag. Comments welcome.

Installing Ruby & Rails on Mac OSX Mavericks

Install homebrew.

$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
@sergii
sergii / helper.rb
Last active August 29, 2015 14:08 — forked from gouthamvel/helper.rb
require 'active_support/core_ext/hash/keys'
class Hash
def recursively_symbolize_keys!
self.symbolize_keys!
self.values.each do |v|
if v.is_a? Hash
v.recursively_symbolize_keys!
elsif v.is_a? Array
v.recursively_symbolize_keys!
@sergii
sergii / hooks.rb
Last active August 29, 2015 14:10 — forked from enajski/hooks.rb
require 'pry'
After( '@developing' ) do |scenario|
binding.pry if scenario.failed?
end
@sergii
sergii / .bashrc
Last active August 29, 2015 14:12
make ()
{
start=$(date +%s);
if command make "$@"; then
icon=checkbox;
else
icon=computer-fail;
fi;
nl='
';
@sergii
sergii / redis.rb
Last active August 29, 2015 14:13 — forked from pubis/redis.rb
#config/initializers/redis.rb
require 'redis'
require 'redis/objects'
REDIS_CONFIG = YAML.load( File.open( Rails.root.join("config/redis.yml") ) ).symbolize_keys
dflt = REDIS_CONFIG[:default].symbolize_keys
cnfg = dflt.merge(REDIS_CONFIG[Rails.env.to_sym].symbolize_keys) if REDIS_CONFIG[Rails.env.to_sym]
$redis = Redis.new(cnfg)
Redis::Objects.redis = $redis