Migrate a Single Database Migration

rails console
require "db/migrate/20121130134444_add_column_backorder_to_orders.rb"
AddColumnBackorderToOrders.up

Convert a Date String to Ruby Date

Date.parse '2013/1/15'

DateTime.parse('2013/1/15'+'-23:59:59-6:00')

Form helper from console

From the rails console.

helper.text_field :object, :name

"<input id="object_name" name="object[name]" size="30" type="text" />"

Set default value in rails model

I like to set default values in my models. This is the method I like to use.

def after_initialize
  if new_record?
    self.upper_quantity ||= 0.0
  end
end

Failed to Connect to a Master Node at Localhost:27017

Everytime my server looses power, Mongo has trouble restarting. These commands fixes the problem.

sudo rm /var/lib/mongodb/mongod.lock
sudo -u mongodb mongod -f /etc/mongodb.conf --repair
sudo service mongodb restart
Previous Next