Jonathan B. Abatayo

My personal blog.

Saturday, January 27, 2007

Ruby on Rails (notes for observers)

OBSERVERS

lib/inventory_init.rb
ActiveRecord::Base.observers = [:item_observer,
:item_supplier_observer]


config/environment.rb
require 'inventory.init'
config. load_path += %W(#RAILS_ROOT/app/observers)


class ItemObserver < ActiveRecord::Observer
def before_create(record)
#code here
end
def after_create(record)
#code here
end
end

def before_update(record)
@status = record.status
end

def after_update(record)
if @status == record.status
# Your code here.
end
end

Ruby on Rails Find or Create

sample Code:
row = Category.find_or_create_by_name("General")
row = ItemSupplier.find_or_create_by_suplier_id(1,2)

Tuesday, October 31, 2006

Creating projects in rails

Create Project:
  • rails <project name>
Run the server:
  • mongrel_rails start -p <port> -d
Migrate:
  • rake migrate
  • rake migrate VERSION=<version number>
Generate scripts:
  • ruby script/generate model <model name>
  • ruby script/generate controller <controller name>
  • ruby script/generate migration <migration name>
  • ruby script/generate plugin <plugin name>

How To Install Ruby On Rails In Windows

$ gem install rails --include-dependencies
$ gem install win32-service
$ gem install mongrel
$ gem install mongrel_service

Sample Codes in phptarsier Ajax

Ajax::remote_form
Ajax::remote_anchor

<div id="placeholder"> </div>

<?= Ajax::remote_anchor('Fill in the Blanks',
     array(t_action => 'ajax_fill'),
     array(
       'update' => 'placeholder',
       'success' => Html::effects:highlight
     )
) ?>