Navigation

Entries in rails (3)

Monday
Jun062011

Ubuntu RVM Rails pre install

I have a weird issue where I wipe and re-install operating systems all the time. Because of this, I decided to create a shell script that will install all the prerequisites for rvm, install and configure rvm and then install rails. Currently, it is set to install rails --pre (currently Rails 3.1.rc1).

#!/bin/bash

echo "Installing dependencies"

sudo apt-get install ruby curl bison build-essential autoconf zlib1g-dev libssl-dev libxml2-dev libreadline6-dev git-core subversion sqlite3

echo "Installing RVM"
bash < <(curl -s https://rvm.beginrescueend.com/install/rvm)

echo "Configuring RVM"
echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bashrc
source ~/.bashrc

echo "Installing ruby 1.9.2-head"
rvm install 1.9.2-head

echo "Setting ruby 1.9.2-head as default"
rvm use 1.9.2-head --default

echo "Installing rails pre"
gem install rails --pre --no-ri --no-rdoc

Just run

source ubuntu_rvm_rails.sh

It will ask you for your sudo password and to confirm the installed dependencies.

Wednesday
Jun012011

Subdomain routing with rails 3.1

I wanted to use subdomain based routing on my current rails 3.1rc project and was getting some very odd behavior. Everything locally worked great when I was using lvh.me to point to local host and using custom subdomains and routes. I used the tutorial found here http://asciicasts.com/episodes/221-subdomains-in-rails-3 to help me with everything and made my own unimportant changes as needed. When I pushed all this up to heroku's bamboo stack, I experienced quite a few errors, but mainly a TypeError (can't convert Symbol into String).

After trying to figure it out on my own, I contacted the heroku support team and they advised me to move it to the brand new cedar stack launched that morning. I did and still experienced the same issue. However, and this is where things really get weird, it stopped working locally. I was really shooting in the dark on this as I had no idea where the error was occurring. I wasn't sure if it was my code or something inside rails or what. After commenting out pretty much every piece of code I had written, I finally found the error. 

At the bottom of the tutorial, he talks about setting the domain for the session cookie so that it is accessible on all domains. The problem is the symbol assigned to the domain key in the hash passed to the session_store method. I guess this worked in 3.0 but is broken in 3.1. By making the following change (setting the domain to your specific domain), everything started working as I expected.

The problem here is that when I am testing locally, I have to remember to change this to lvh.me or set my hosts file to point my personal domain to 127.0.0.1. At least it is working agian.

Monday
May302011

Hosting with heroku

I am working on a side project that uses Rails 3.1rc since I am just starting development. I know that it is pretty early on but heroku's platform is pretty well sandboxed for each application so I figured if I can get something up and running locally using thin and just gems installed via my gemfile, things would work fine on heroku. I did have to install 'pg' in order to get it to work with heroku's postgresql database, but that was it. Except now, everything seems to get processed successfully to the point where the log files say "Completed 200 OK in 7ms(...)" yet 2 lines later, it says TypeError (can't convert Symbol into String). It would be nice to get some line numbers or stack trace with the logs to identify where the error really occured. I know, I am trying to use their system with an RC product, but the point is still valid. Better logs, happier customers.