Setting up a Ruby on Rails (RoR) website.
RoR!
Date Created:Thursday July 31st, 2008 02:13 PM
Date Modified:Thursday July 31st, 2008 02:14 PM
| _ _
=== |.===. '\\-//`
(o o) {}o o{} (o o)
ooO--(_)--Ooo-ooO--(_)--Ooo-ooO--(_)--Ooo-
First, set up your rails project:
rails yoursite.com
Navigate into your project:
cd yoursite.com
Set up the database file:
vi config/database.yml It should look something like this: development: adapter: mysql database: test timeout: 5000 test: adapter: mysql database: test timeout: 5000 production: adapter: mysql database: test timeout: 5000
Generate a model:
script/generate model book
edit the file containing the table structure for the model:
vi db/migrate/001_create_books.rb
Change the file to this:
class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.column :title, :string
t.column :author, :string
t.column :isbn, :string
t.column :subject, :string
t.timestamps
end
end
def self.down
drop_table :books
end
end
Initiate the migration:
rake db:migrate
Then edit the model itself:
vi apps/models/book.rb
class Book < ActiveRecord::Base
validates_presence_of :title
validates_presence_of :author
end
Now create the controller and then scaffold:
script/generate controller book script/generate scaffold book book
Downloads:
Download: book.rb 113 B
Please login or Click Here to register for downloads
Begin a Rails Project by Dan Lynch
is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License
Based on a work at www.3daet.com
Permissions beyond the scope of this license may be available at http://www.3daet.com
