Wednesday 29 February 2012

Developing SQLite3 and Postgres for use with Heroku

So Heroku's FAQ on using SQLite3 alongside Postgres basically consists of "Don't", so in the usual spirit of things, I'm out to make it work. Why you want to do this is up to you, for me it is because the Postgres gem forces the JSON gem to install with Native Extensions instead of just using JSON and all the university machines have ANSICON which breaks JSON via a registry entry. Also even if it did work I don't think they will let me install Postgres on their machines so SQLite3 is a must.

There were many pitfalls on the way to discovering this since I was stubborn but it turns out there is a really pretty and simple way to do this.
We must separate production from development and test as Heroku uses production.

In gemfile

group :production do
  gem 'pg'
end


group :development, :test do
  gem 'sqlite3'
end


And that is it.

Bask in Rails server for development in SQLite3,

Heroku login, Heroku create --stack cedar, Git push heroku master, Heroku run rake db:migrate, Heroku open.

Then revel in your working heroku production environment.

I even went so far as to play with many things like Bundle install --without production and rake db:migrate RAILS_ENV=development but you should not need to play with such things.

That is all.

Tuesday 28 February 2012

My exact RoR environment (Code Only)

sudo apt-get install xinit
sudo apt-get install fluxbox
sudo apt-get install ruby1.9.1-dev
" permission denied - /var/lib/gems " if not using 'sudo' for gem install
sudo gem install sqlite3
if "Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
        ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb " then sudo apt-get install sqlite3 libsqlite3-dev
sudo gem install rspec
if "make
sh: make: not found " then sudo apt-get build-essential
sudo gem install rails
sudo gem install rspec-rails
sudo gem install cucumber-rails
if "libxml2 is missing." then sudo apt-get install libxml2-dev
if "libxslt is missing." then sudo apt-get install libxslt-dev
if "could not find gem 'jquery-rails (>=0) ruby' in any of the gem sources listed in your Gemfile."
"/var/lib/gems/execjs-1.3.0/lib/execjs/runtimes.rb:50:int 'autodetect': Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)" then
sudo add-apt-repository ppa:chris-lea/node.js
if "the program 'add-apt-repository' is currently not installed."
sudo apt-get install python-software-properties
sudo apt-get install nodejs
startx
Add editor of choice and done.

Sunday 26 February 2012

Rails 3 on Ubuntu11.04 (11.10)

It seems that when asked how to install Rails on Ubuntu everyone immediately points to RVM and to be honest, there are many good reasons to. Just in case you don't want to use RVM for whatever reason and choose to walk the other path, there are plenty of pitfalls to consider there.

Things to note:
I'm starting with a new Ubuntu Server 11.04 on a VirtualBox  (Edit:Version 11.10 as of 26/02/2012)

The only commands I've used before this is sudo apt-get install xinit and sudo apt-get install fluxbox but I am not running either of those packages while getting ruby or rails. I just like having a text editor and terminal up at the same time.


Edit: This also works exactly the same on Ubuntu Desktop x64 v11.10

Installing without RVM


We are going to need the compilers included in build-essential in order to build native extensions of gems later.
sudo apt-get install build-essential 
We are going to need sqlite3 also
sudo apt-get install sqlite3 libsqlite3-dev
The name is ruby1.9.1 but this is 1.9.2, testable by using the ruby -v command after you have installed it. Also you must use the -dev version as the ruby1.9.1 does not include some dependencies needed to run itself due to the Debian packaging system (according to a Google search)
sudo apt-get install ruby1.9.1-dev
sudo gem install rails
Rails at this point will not run as we will not have a Javascript engine. TheRubyRacer is officially advised against by Heroku so lets go for Node.Js for now
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
You should now be adle to start a Rails app and run Rails server without Rails yelling at you about Javascript.
Now is the time to install any gems you like, lets go for RSpec and Cucumber and their Rails variants to start with.
sudo gem install Rspec
sudo gem install Cucumber
sudo gem install Rspec-Rails
Before we can install the cucumber-rails gem we need to make sure we have a couple more packages or we will experience strange errors.
sudo apt-get install libxslt-dev libxml2-dev
Now we can get Cucumber-Rails in peace
sudo gem install Cucumber-Rails

If there is anything missing please comment below so others can see it.
I will keep updating this post with any error messages that you can encounter along with their fixes so people can google their way here, in making this I ran into multiple errors that were unique or variants of other errors only.
~Greg Myers
~BookOfGreg