Creating a new rails app

So…once you get it going how do you actually make rails work?

it’s not too bad

1) start a rails project.

rails projectName

2) Setup the DB to be what you want it to be (create migrations to setup the tables).

cd projectName
rake generate migration thisIsItsName

edit configure\db.yml to use sqlite3:

adapter: sqlite3
database: db/podCastBlender_development

adapter: sqlite3
database: db/podCastBlender_test

adapter: sqlite3
database: db/podCastBlender_production

3) run
ruby script/generate scaffold allthedatabasenames repeatthosenames
to setup some trivial database accessors/modifiers.

4) edit the models to reflect the ‘real’ relationships between the tables.
Say you have one named “users” and one named “objects” where each user has many objects?
The table for “objects” should be setup to have a field “user_id” (if user is the name of the owner)

then models\user.rb (each user has many objects, remember) is as follows:

class User < ActiveRecord::Base has_many :objects end

and objects.rb
class User < ActiveRecord::Base belongs_to :user end
[belongs_to means "I have a row that is the [primary] ID of this other entry in that table"

5) add code to use those relationships before saving the objects (like assign a user)--just a good idea generally 🙂

6) Do what you really wanted to do with the pages, etc.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload the CAPTCHA.