Posts Tagged Ruby and Rails
Rails 3.1 on Heroku, TLDR Version
Posted by John in Ruby and Rails on December 13, 2011
Create the app
- If not installed, install PostgreSQL
rails new app_name -T -d=postgresqlcd app_name/rvm --create --rvmrc 1.9.2@app_namervm rvmrc trust- Edit .Gemfile
bundle installcreateuser -P -S -R -d app_name(no to ‘Superuser’ and ‘Create roles’, yes to ‘Create databases’)rake db:create- Create procfile in app root.
foreman startand check http://0.0.0.0:5000/
Push to Github
- Edit .gitignore
git flow initgit add .git commit -m 'Project skeleton'- Create app_name on Github
git remote add origin git@github.com:JohnPlummer/app_name.gitgit push -u origin developgit push -u origin master
Push to Heroku
heroku create app-name --stack cedargit flow release start '0.0.1'git flow release finish '0.0.1'git push --allgit push heroku masterheroku run rake db:seedheroku open
Installing Postgresql and pgAdmin
Posted by John in Ruby and Rails on December 6, 2011
The default database for Heroku is PostgreSQL and, while you could use SQLite for development and Postgres for production, there are some inconsistencies between the two. Ideally you would use the same version of the database server but currently Heroku uses version 9 for dedicated databases and 8.3 for shared databases and seem to recommend you install the latest version for development.
Install Postgres with Homebrew with brew install postgresql and follow the instructions after the install to initialise a database.
initdb /usr/local/var/postgres
The database server can be set to start at login with
mkdir -p ~/Library/LaunchAgents
cp /usr/local/Cellar/postgresql/9.1.1/org.postgresql.postgres.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/org.postgresql.postgres.plist
But I prefer to add aliases to .bashrc to start and stop the server:
alias pgs='pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start'
alias pgq='pg_ctl -D /usr/local/var/postgres stop -s -m fast'
Postgres can be managed with the command line utility psql but, as much as I like the command line, I don’t really want to have to write SQL to edit or remove a user role. PgAdmin is a free GUI for Postgres management. Once installed, ensure the Postgres server is running then run pgAdmin and connect to the server.
In the server properties add a name for the connection and add your login as the username.

pgAdmin provides the management tools you would expect.

Learning Ruby (on Rails)
Posted by John in Ruby and Rails on December 15, 2010
Most of my programming career has revolved around Microsoft technologies, starting with Visual Basic 3, up through the various versions to VB.Net, then switching to CSharp shortly after DotNet came out of beta.
I think I know the MS development stack fairly well and I like the direction they are moving in with the likes of MVC3 and Razor, Nuget etc. but it seems a fair amount of this ‘direction’ may be coming from the Rails community.
I have decided to give myself 2 weeks to ‘learn’ Rails, although I may get distracted by the Christmas holidays (and the fact that we will have an extra 6 kids and 3 adults staying with us for 2 weeks) and will record some of it here.
I have done a little research in preparation and bought a couple of ebooks from the prags:
They seem to be considered ‘definitive’ and cover the current versions of Rails (3.0.3) and Ruby (1.9.2).
The only other purchase I am likely to make is an IDE or editor. I code on a Mac, even when using Visual Studio so I have a few more options than most Windows users. The recommendation seems to be that, if you are on Windows, install a Linux VM for Ruby development. The favourite environment for the Mac looks to be Textmate although there are a few IDEs available such as JetBrain’s RubyMine and Aptana Studio, both of these are available for Windows, OS x, and Linux. I am a fan of JetBrain’s Resharper so will try RubyMine, the trial is 30 days so no need to make a purchase decision yet.
Other references that I expect to find useful over the next 2 weeks are: