Nurulazrad Blog


Posts tagged with "rails"

osx - Can't get Phusion Passenger working with Mac OS X Mountain Lion and Apache - Stack Overflow

future reference… it seems easy when it’s working… nonetheless good to have it tumblr-ed in my account.

Deploying with Capistrano without Rails

With a combination of railsless-deploy, allows other non-rails developer to use Capistrano as a tool for automating tasks on one or more servers.

RailsConf Keynote: David Heinemeier Hansson

With the release of Rails 1.2 we take a look back at David Heinemeier Hansson’s RailsConf keynote from Chicago.

Oct 5

.sum returns wrong number of arguments error

Recently, I just started my own Ruby on Rails project based on one of my client requirement. The app got up and running in just two (2) hours time, I’m impressed. (not to myself, but the RoR framework).

I’ve setup my models as follows:

class Report

has_many :items


class Item

belongs_to :report


so when i do:

class ItemsController

def list

@report = Report.find(params[:report_id])

@items = @report.items

@total_price = @items.sum { |item| item.unit_price * item.quantity }



As a result, it returns “wrong number of arguments (1 for 2)” error.

After doing some testing on the variable @items, it turns out that I need to change the @items to Array using .to_a, thus the code is updated as follow:

# ItemsController

def list

@report = Report.find(params[:report_id])

@items = @report.items.to_a

@total_price = @items.sum { |item| item.unit_price*item.quantity }


Hope others who has problem with this will benefits from this.

Setup mod_rails Phusion - Mac OS X: Leopard

How to setup mod_rails using Phusion on Mac OS X

Downgrade Rails version

This morning, I’ve just installed Rails-version-3.0.0-beta for testing. Of course, using root account to the ‘gem install’ command

% gem update —system

% gem install tzinfo builder memcache-client rack rack-test rack-mount erubis mail text-format thor bundler i18n

% gem install rails —pre

And please make sure you have upgrade your Ruby to version 1.8.7, you can use rvmto install ruby. With rvm, you can have multiple Ruby and rvm allows you to choose which version you want to use.

But, for me, I skip to install the rvm and boom, when i do ” rails -v”, it shows me:

% rails -v

Rails 3.0.0 beta3

Now, I’m having problem switching to stable Rails version. As usual, googling does help me to get stable version of Rails. To see all rails version on your Mac/PC, do this:

% gem list rails

*** LOCAL GEMS ***

rails (3.0.0.beta3, 2.3.5, 2.3.4, 2.3.2, 2.2.2, 1.2.6)

Next, to tell your rails to use which version, is simply by using the following command:

% rails _2.3.5_ myProject

and to see myProject rails version is by typing:

% cd /path/to/myProject

% script/about

About your application’s environment

Ruby version              1.8.7 (universal-darwin10.0)

RubyGems version          1.3.6

Rack version              1.0

Rails version             2.3.5

Active Record version     2.3.5

Active Resource version   2.3.5

Action Mailer version     2.3.5

Active Support version    2.3.5

Application root          /Library/WebServer/Documents/rails/fms

Environment               development

Database adapter          sqlite3

Database schema version   0