Rails – Getting Started

5 Sep

Useful rails commands.

To get a basic rails page going:
1. Get rails up to date
$> gem update -y –include-dependencies

2. Get the generic rails stuff into this directory
$> rails stock

3. Create the model (i.e. the database)

a. Create the schema for a table called ‘Stock’ with the ‘name’, ‘code’, ‘price’ and ‘sector’ columns
$> ruby script/generate scaffold_resource Stock name:string code:string price:integer sector:string

b. edit config/database.yml to define your development db (you might wanna use sqlite), e.g.

  adapter: sqlite
  database: db/stock_development
  username: root

(Note i had to install sqlite and libsqlite-dev as well as do a ‘gem install sqlite’ to get this to work)

c. Execute the sql
$> rake db:migrate

4. Create routing
Edit config/routes.rb to map the table name and add the controller name.
(Note the controller name is the same as the name in app/controllers/stocks_controller.rb)

map.resources :stocks


map.connect '', :controller => "stocks",:action=>"index"

5. Start the server with WebRick the dev webserver
$> ruby script/server webrick

6. Go to the page with a webserver

Powered by ScribeFire.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: