Posts Tagged Ruby and Rails

Rails 3.1 on Heroku, TLDR Version

Create the app

  1. If not installed, install PostgreSQL
  2. rails new app_name -T -d=postgresql
  3. cd app_name/
  4. rvm --create --rvmrc 1.9.2@app_name
  5. rvm rvmrc trust
  6. Edit .Gemfile
  7. bundle install
  8. createuser -P -S -R -d app_name (no to ‘Superuser’ and ‘Create roles’, yes to ‘Create databases’)
  9. rake db:create
  10. Create procfile in app root.
  11. foreman start and check http://0.0.0.0:5000/

Push to Github

  1. Edit .gitignore
  2. git flow init
  3. git add .
  4. git commit -m 'Project skeleton'
  5. Create app_name on Github
  6. git remote add origin git@github.com:JohnPlummer/app_name.git
  7. git push -u origin develop
  8. git push -u origin master

Push to Heroku

  1. heroku create app-name --stack cedar
  2. git flow release start '0.0.1'
  3. git flow release finish '0.0.1'
  4. git push --all
  5. git push heroku master
  6. heroku run rake db:seed
  7. heroku open

, , , , , , ,

No Comments

Installing Postgresql and pgAdmin

 

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.

Server  1

pgAdmin provides the management tools you would expect.

PgAdmin III

 

, , ,

No Comments

Learning Ruby (on Rails)

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:

, , , , , , , , , , , , , , , , , , , , , , ,

1 Comment