Thursday, March 6, 2008

New Rails 2.0.2 file

$ rails appName -d mysql appName
$ cd appName
$ rake rails:freeze:gems
$ rake db:create
$ [script/generate scaffold neededTableName columnName:dataType, ...]
$ mate .
(further configure migrations as needed)
$ rake db:migrate

Unix delete dir+contents

rm -r dir

Tuesday, March 4, 2008

More Rails 2.0

migrations-->foreign key--> t.references :table_name

Monday, March 3, 2008

Dream SSH access

ssh username@domain_name.com
pwd

RoR: From RyanB's Railscasts

Model.find_all_by_columnName(condition); --or simply find_by_columnName

Class method=> def self.method_name; move multi-use methods from controller to model

with_scope :method_root (ex. :find) => options do
method code
end

when iterating through blocks w/ method--> method to proc --> ex. find(:all).collect(&:name)

virtual attribute--> acts like any column--> define getter and setter methods w/ attribute name in model.
ex.
def full_name
[first_name, last_name].join(' ')
end

def full_name=(name)
split = name.split(' ', 2)
self.first_name = split.first
self.last_name = split.last
end
Named routes--> generic --> map.resources :modelName
custom-->map.custom_name ("route_root/:param1/:param2"), :controller=>controller_name, :action=>action_name

Seven default named routes embedded in map.resources :modelName
  • Index
  • Show
  • New
  • Create
  • Edit
  • Update
  • Destroy

fixtures --> dummy data moves with filesystem

add/remove columns to existing from prompt -->script/generate migration [add/remove]_columnName_[to/from]_tableName

new App--> need DB--> rake db:create

make_resourceful plugin-->
script/plugin install http://svn.hamptoncatlin.com/make_resourceful/tags/make_resourceful

in Controller:
make_resourceful do
actions :all
end