Who is Jeremy Tennant

Posted by Jeremy in Uncategorized

27 years old / Melbourne / Australia / Entrepreneur / Rookie Developer / Geek / Photographer / ITIL guy

I have a wide range of interests, however for the most part, I’m using this blog to document key learnings and knowledge as I continue to learn Web Development using Ruby on Rails.

I genuinely hope that the articles in my blog help others who are also learning Rails, however I am unable to attest to the suitability of any of the articles for your particular situation.

Ruby 1.9.3 + Rails 3.2.3 + Fresh Ubuntu 12.04 Issues [Via RVM]

Posted by Jeremy in OSX/Linux Terminal Stuff, Rails

I recently completed Michael Hartl’s excellent online book; a Ruby on Rails tutorial that allows you to learn via doing. I told one of my mates about it and convinced him to do the same.

I use OSX, so everything worked swimmingly for me. Unfortunately, I had a really tough time helping my mate deploy ruby and rails to a fresh Ubuntu installation, so I sent him on his way to try again another time.

Firing up a Virtual Machine later in the evening (ie now, whilst I’m typing this), I actually received the same issues as I did on his laptop – this was a fresh Ubuntu 12.04 LTS install!

And so, with that in mind, I sought to resolve the issue. If you’re also experiencing issues with zlib, openssl or other missing packages, here is my winning formula!

  1. First, I imploded my existing RVM install, this gave me a fresh start rvm implode
  2. I installed RVM (make sure you have git-core and curl installed before you do this [use apt-get]) curl -L get.rvm.io | bash -s stable and then source ~/.rvm/scripts/rvm based on instructions at rvm.io
  3. I installed zlib manually via rvm  rvm pkg install zlib
  4. I installed openssl manually via rvm  rvm pkg install openssl
  5. I installed ruby with the following args rvm reinstall 1.9.3 --with-openssl-dir=$rvm_path/usr
  6. I installed some additional packages  sudo apt-get install libxslt-dev libxml2-dev libsqlite3-dev as per Michael’s recommendation
  7. I installed rails gem install rails -v 3.2.3
Hopefully that helps you as well!
Final thought: I wasn’t able to run rails server for my test app on this fresh install either; by default there isn’t a javascript runtime. I installed nodejs.

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs npm

Setting up a brand new rails app

Posted by Jeremy in Rails

/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * Michael Hartl wrote this code. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.
 * ----------------------------------------------------------------------------
 */

Sourced from here: http://ruby.railstutorial.org/chapters/static-pages

Create the app
rails new APPNAME --skip-test-unit

Sample Gemfile

source "https://rubygems.org"

gem "rails", "3.2.3"
gem "bcrypt-ruby", "~> 3.0.1"
gem "faker", "~> 1.0.1"
gem "pg", "~> 0.13.2"
gem "will_paginate", "~> 3.0.3"
gem "bootstrap-sass", "~> 2.0.2"
gem 'bootstrap-will_paginate', '0.0.5'

group :assets do
gem "sass-rails", "~> 3.2.3"
gem "uglifier", ">= 1.2.4"
end
gem "jquery-rails"

group :development, :test do
gem "rspec-rails", "~> 2.10.1"
gem "guard-rspec", "0.7.0"
end

group :test do
gem "capybara", "~> 1.1.2"
gem "rb-fsevent", "~> 0.9.1"
gem "growl", "~> 1.0.3"
gem "guard-spork", "~> 0.8.0"
gem "spork", "~> 0.9.1"
gem "factory_girl_rails", "~> 3.2.0"
end

Install the gems
bundle install --without production

Use Rspec instead of test unit
rails generate rspec:install

Initialise a git repo
git init
git add .
git commit -m "First commit"

Then visit github and setup a new app. Then push it to github
git remote add origin git@github.com:jeremydt/APPNAME.git
git push -u origin master

Push to Heroku
heroku create --stack cedar
git push heroku master

RVM Bundler Integration
rvm get head && rvm reload
chmod +x $rvm_path/hooks/after_cd_bundler
cd ~/rails_projects/SAMPLEAPP
bundle install --without production --binstubs=./bundler_stubs

Sample .gitignore file

# Ignore bundler config
/.bundle

# Ignore the default SQLite database.
/db/*.sqlite3

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp

# Ignore other unneeded files.
doc/
*.swp
*~
.project
.DS_Store
bundler_stubs/

If an executable is installed during the duration of the project, run this
bundle --binstubs=./bundler_stubs

Initialise Guard so that it works with rspec
bundle exec guard init rspec

Sample Guardfile

require 'active_support/core_ext'

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch(%r{^config/environments/.+\.rb$})
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb')
  watch('test/test_helper.rb')
  watch('spec/support/')
end

guard 'rspec', :version => 2, :cli => '--drb' do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb') { "spec" }

  # Rails example
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
  watch('spec/spec_helper.rb') { "spec" }
  watch('config/routes.rb') { "spec/routing" }
  watch('app/controllers/application_controller.rb') { "spec/controllers" }
  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |m|
    ["spec/routing/#{m[1]}_routing_spec.rb",
     "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
     "spec/acceptance/#{m[1]}_spec.rb",
     "spec/requests/#{m[1].singularize}_pages_spec.rb",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" :
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    "spec/requests/#{m[1].singularize}_pages_spec.rb"
  end
end

Run this, as guard has been installed
bundle --binstubs=./bundler_stubs

Bootstrap the Spork configuration:
bundle exec spork --bootstrap

Sample spec/spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.
  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    # == Mock Framework
    #
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
    #
    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr
    config.mock_with :rspec

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

Run this, as spork has been installed
bundle --binstubs=./bundler_stubs

Run Spork, then cancel
bundle exec spork

Create a .rspec file in the root, add these lines so that spork is run automatically with gaurd.
--colour
--drb

Use Guard with Spork
bundle exec guard init spork

Things I forget about when using git/github

Posted by Jeremy in git

Deleting a local and remote (github) branch
git push origin --delete BRANCHNAME

Pushing a branch to github
git push REMOTENAME BRANCHNAME

Checkout a remote branch
git fetch origin
git checkout --track origin/BRANCHNAME

Commands I should remember, but always forget.

Posted by Jeremy in OSX/Linux Terminal Stuff

I’ll update this post as I think of things.

Disable the warning when changing a file extension

Posted by Jeremy in Post OSX Install

defaults write com.apple.finder FXEnableExtensionChangeWarning -bool false

Avoid creating .DS_Store files on network volumes

Posted by Jeremy in Post OSX Install

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true

Enable AirDrop over Ethernet and on unsupported Macs running Lion

Posted by Jeremy in Post OSX Install

defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool true

Disable press and hold in favour of key repeat

Posted by Jeremy in Post OSX Install

defaults write NSGlobalDomain ApplePressAndHoldEnabled -bool false

rb-fsevent build/install error

Posted by Jeremy in Rails

When installing the Ruby Gem fsevent, I was getting the following error

An error occured while installing rb-fsevent (0.4.3.1), and Bundler cannot continue.
Make sure that `gem install rb-fsevent -v ’0.4.3.1′` succeeds before bundling.

Resolved by:

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/

and then re-running bundle install