Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save p1nox/8909754 to your computer and use it in GitHub Desktop.
Save p1nox/8909754 to your computer and use it in GitHub Desktop.

##References

##Create Rails App

command to make new directory:

mkdir AppName

command to create new rails app:

rails new AppName

command to move to app directory:

cd AppName

##Rev Up Git

command:

git init

command:

git remote add origin [github url]

command:

git add .

command:

git commit -m "initial commit"

command:

git push origin master

##Rev Up Heroku

###Create dev and prod environments command to create dev:

heroku create --stack cedar --remote dev

command to rename dev:

heroku rename [AppName] --remote dev

command to create dev:

heroku create --stack cedar --remote prod

command to rename dev:

heroku rename [AppName] --remote prod

###Install Heroku add-ons (prod example) command to add custom domain app:

heroku addons:add custom_domains --remote prod

command to add domain:

heroku domains:add example.com --remote prod

command to add pg backup app:

heroku addons:add pgbackups --remote prod

command to upgrade pg backup app:

heroku addons:upgrade pgbackups:auto-month --remote prod

command for email needs:

heroku addons:add sendgrid:starter --remote prod

command to run migrations:

heroku run rake db:migrate --remote prod

###Set up NewRelic

Command line instruction

heroku addons:add newrelic:standard

Add this line to the Gemfile

gem 'newrelic_rpm'

Run the install

bundle install

Add this script to a new file named config/newrelic.yml with this command

curl https://raw.github.com/gist/2253296/newrelic.yml > config/newrelic.yml

##Set up Gemfile

add to gemfile:

group :test do
  gem 'sqlite3'
end

group :development do
  gem 'sqlite3'
end

group :production do
  gem 'pg'
end

command:

bundle install

##Set up RSpec

add to gemfile:

group :test do
  gem 'rspec-rails'
end

group :development do
  gem 'rspec-rails'
end

command:

bundle install

command:

rails generate rspec:install

##Set Up ActiveAdmin

add to gemfile:

gem 'activeadmin', :git => 'https://github.com/gregbell/active_admin.git'
gem 'sass-rails', '~> 3.2.3'
gem "meta_search",    '>= 1.1.0.pre'

remove from gemfile assets group:

gem 'sass-rails', '~> 3.2.3'

command:

bundle install

command:

rails generate active_admin:install

command:

rake db:migrate

test your setup and sign-in at:

http://[site.com]/admin
un: admin@example.com
pw: password

go to config/environments/development.rb and add this line:

config.action_mailer.default_url_options = { :host => 'localhost/3000' }

go to config/environments/production.rb and add this line:

config.action_mailer.default_url_options = { :host => 'domain.of.site.com' }

create config/initializers/mail.rb and add this script:

ActionMailer::Base.smtp_settings = {
  :address        => 'smtp.sendgrid.net',
  :port           => '587',
  :authentication => :plain,
  :user_name      => ENV['SENDGRID_USERNAME'],
  :password       => ENV['SENDGRID_PASSWORD'],
  :domain         => 'heroku.com'
}
ActionMailer::Base.delivery_method = :smtp

add these lines to config/application.rb:

config.assets.initialize_on_precompile = false
config.assets.precompile += %w[active_admin.css active_admin.js print.css]
config.assets.precompile += %w[active_admin/print.css]

###Register/Setup the AdminUser with ActiveAdmin

command:

rails generate active_admin:resource AdminUser

go to app/admin/admin_users.rb and add this block:

ActiveAdmin.register AdminUser do
  index do
    column :email
    column :current_sign_in_at
    column :last_sign_in_at
    column :sign_in_count
    default_actions
  end
 
  form do |f|
    f.inputs "Admin Details" do
      f.input :email
    end
    f.buttons
  end
end

go to app/models/admin_models.rb and add this line:

after_create { |admin| admin.send_reset_password_instructions }

add this block:

def password_required?
  new_record? ? false : super
end

###Set Up Some Models

command:

rails generate model Post name:string

command:

rake db:migrate

###Register a model with ActiveAdmin

command:

rails generate active_admin:resource [ModelNameSingular]

###Edit ActiveAdmin config

  • go to config/initializers/active_admin.rb for basic settings

  • go to app/admin/dashboards.rb for the dashboard

###Adjust for the mass assignment security changes

Make this edit to your respective model files at /app/models/model_name.rb:

class User < ActiveRecord::Base
  attr_accessible :firstname, :lastname, :age

end

##Handle Error Pages

Add to config/routes.rb file:

match '*a', :to => 'errors#routing'

Create app/controllers/errors_controller.rb and add this script:

class ErrorsController < ApplicationController
def routing
  render :file => "#{Rails.root}/public/404.html", :status => 404, :layout => false
  end
end

Set up a monitoring page

###Create a boring view at app/views/static/monitor.html.erb

Monitoring Page

###Create a boring template at app/views/layouts/monitor.html.erb <title>IndyCar Laps</title> <%= stylesheet_link_tag "application", :media => "all" %> <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> <%= yield %>

###Set up your controller file at app/controllers/static_controller.rb # GET /monitor def monitor render :layout => 'monitor' end

###Set up the route in your config/routes.rb file match 'monitor' => 'static#monitor'

##Push to Prod or Dev

command to add files to git:

git add .

command to commit files to git:

git commit -m "installing ActiveAdmin"

command to push to Github:

git push origin master

command to push to Dev:

git push dev master

command to push to Prod:

git push prod master

##Errors

###Locked out of the default admin user

Run the console:

heroku run console OR ruby console

Run this line in the rails or heroku console:

AdminUser.create!(:email => 'admin@example.com', :password => 'password', :password_confirmation => 'password')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment