This accompanies the rails notes page.
What is Rails discussion.
Download/install InstantRails
Unzip InstantRails and move the InstantRails folder to
the C:/ folder.
Instant Rails will detect that it is being started from a new directory and ask if you want to have it update the paths in the all of the configuration files… Just say yes.
Click on the I button to drop down the main menu and select Configure > Windows Hosts file.
In the editor that pops up, add this line to the end of the file:
127.0.0.1 blogr.com
Save the change and exit the editor.
In the main menu, select Rails Applications > Manage Rails Applications…
Run rails blogr from command line and enter the
newly-created blogr directory with cd blogr.
Start local mysql server and create the three local databases,
In MySQL language, this is
CREATE DATABASE blogr_development; CREATE DATABASE blogr_test; CREATE DATABASE blogr_production;
Modify blogr/config/database.yml to reflect the new local server. E.g.,
development: adapter: mysql database: blogr_development socket: /Applications/MAMP/tmp/mysql/mysql.sock user: root password: root
Run ruby script/server to start the local WEBRick server
Navigate to http://localhost:3000 and make sure everything checks out: click the “About your application’s environment” link and ensure you don’t get any warnings.
Stop the WEBRick server by going to the console where you started it and hitting Control+C.
MVC Discussion
Schema discussion:
stories: authors: id +-> id title | title slug | email story | password created_at | created_at updated_at | author_id <——-+
Generate the scaffolding for stories by running
ruby script/generate scaffold Story \ title:string \ slug:string \ story:text \ author_id:integer
Note that id, created_at, and updated_at are free.
Migrations discussion
Run the migration to add in the new stories columns by running
rake db:migrate.
Scaffolding discussion
Navigate to http://localhost:3000/stories to ensure you get a “Listing stories” page
Add a missing column, rating by using Migrations. Run ruby
script/generate migration add_story_rating. Modify this Migration,
blogr/db/migrate/002_add_story_rating.rb, to be
{{lang:ruby}} class AddStoryRating < ActiveRecord::Migration def self.up add_column :stories, :rating, :integer, :default => 3 end
def self.down remvoe_column :stories, :rating end end
Migrate the database by running rake db:migrate.
Model association discussions:
Also discuss the columns that are added to the tables as a result of these relationships.
blogr/app/models/story.rb becomes
class Story < ActiveRecord::Base belongs_to :author end
blogr/app/models/author.rb becomes
class Author < ActiveRecord::Base has_many :stories end
Author: Ryan Timmons
Last Modified: 06 August 2008 15:23:13 PDT
URL: http://uwwebpub.com/