Skip to content

Instantly share code, notes, and snippets.

@leommoore
leommoore / heroku_basics.markdown
Last active October 1, 2015 19:57
Heroku Basic Commands

#Heroku Basic Commands

gem install heroku
heroku keys:add               #Adds in the keys so that you can remotely access heroku
heroku create --stack cedar   #Create a Heroku site on their Cedar Stack (best for rails 3.1)
git push heroku master        #Pushes the current committed contents up to Heroku 
heroku run rake db:migrate    #Update database migrations
heroku open                   #Opens the current site in your browser (server must be running)
heroku logs #Shows what is happening on the server
@leommoore
leommoore / aws_rails_install
Created March 22, 2012 23:42
Install Rails on AWS Linux AMI instance
http://definenull.com/content/how-install-ruby-and-rails-amazon-ec2-server
To install Ruby and Rails on your Amazon EC2 server there are a few steps you need to follow, but none of them quite hard. By default ruby is already installed on your server by Amazon - check it by running $ ruby -v.
$ ruby -v
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-linux]
For this tutorial I will not be using the Ruby Version Manager - RVM. It has the power to make it easier later to change ruby versions in a contained environment.
Download the RubyGems from RubyForge. The latest version at the moment is 1.8.11.
@leommoore
leommoore / rails_ubuntu_installation.md
Last active October 2, 2015 03:58
Installing Rails on Ubuntu

#Installing Rails on Ubuntu

http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/
----------------------------------------------------------------

sudo apt-get install build-essential git-core curl python-software-properties

curl -L https://get.rvm.io | bash -s stable --ruby --auto-dotfiles
@leommoore
leommoore / font-Awesome.markdown
Last active October 13, 2017 03:30
Using Font-Awesome with Rails 3.1 using CSS

#Using Font-Awesome with Rails 3.1 using CSS

  1. Download font-awesome from https://github.com/FortAwesome/Font-Awesome

  2. Put the font folder in the app/assets. I renamed the folder from font to fonts to make it clearer

  3. Add config.assets.paths << "#{Rails.root}/app/assets/fonts" to config/application.rb. This is to include the apps/assets/fonts folder in the asset pipeline

  4. Put the font-awesome.css file in the app/assets/stylesheets folder

#Primary key finder
Subject.find(2)
Returns an object or an error
#Dynamic Finders
Subject.find_by_id(2), Subject.find_by_name("First Subject")
Returns an object or nil
#Find all Method
Subject.all
#------------------------------------------------------------------------------------------
# One to One Relationship
#------------------------------------------------------------------------------------------
class Subject < ActiveRecord::Base
has_one :page
end
class Page < ActiveRecord::Base
#Class with belongs_to should have the foreign key
#belongs_to :subject, {:foreign_key => "subject_id"}
@leommoore
leommoore / PassengerApacheInstall.markdown
Created April 6, 2012 14:53
Passenger Apache Install

#Passenger Apache Install

First, install passenger. This will help with the rest of the install.

sudo gem install passenger

sudo passenger-install-apache2-module

sudo apt-get install libcurl4-openssl-dev

sudo apt-get install apache2-mpm-prefork

@leommoore
leommoore / RailsCRUD.txt
Created April 6, 2012 16:27
Rails CRUD
CRUD Action Concept
Create new Display new record form
create Process a new record form
Read list List Records
show Display a single record
Update edit Display edit record form
update Process a edit record form
Delete delete Display delete record form
destroy Process delete record form
@leommoore
leommoore / RailsValidation.rb
Created April 6, 2012 21:37
Rails Validation
validates_presence_of
# Attribute must not be blank (nil, false, "", " ",[] ,{})
# :message => "can't be blank"
validates_length_of
# Attribute must meet the length requirements of the options
# :is, :minimum(integer)
# :within, :in(range)
# :wrong_length => "is the wrong length (should be {{count}} characters)"
# :too_short => "is too short (minimum is {{count}} characters)"
@leommoore
leommoore / RailsModelCallbacks.rb
Created April 7, 2012 17:38
Rails Model Callbacks
#Validation
:before_validation # Create, Update
:after_validation # Create, Update
#Database
:before_save # Create, Update
:before_create # Create
:before_update # Update
:before_destroy # Destroy