(Much content based on http://www.netbeans.org/kb/docs/ruby/rapid-ruby-weblog.html)

  • Install Ruby 1.8.6 from the one-click installer.
  • Install MySQL 5.0.27, as a Windows Service, with developer Tools.
  • Install NetBeans 6.5.1 with just the Ruby package.
  • gem update –system
  • gem install mysql
    1. It installed mysql-2.7.3-mswin32.  Note: Only MySQL 5.0.27 works with 2.7.3 of the gem.  That is the version it was linked with when it was compiled.  If you mismatch the versions, you’ll get “rake aborted! undefined method `each' for #<Mysql:…”
    2. It gave an error installing the doc, but the rest appears OK.
  • gem install rails
  • Start NetBeans
    1. File/New Project
      1. Ruby
      2. Ruby on Rails Application
      3. Project Name = rubyweblog
      4. Location=K:\NetBeansProjects
      5. Platform=Ruby 1.8.6-p287
      6. Server=WebRick
      7. Database Adapter=mysql
      8. database name = rubyweblog_development
      9. user=root
      10. Rails Version=2.3.2
    2. Right-click Rubyweblog in the tree
      1. Generate / Scaffold
      2. Model Name = Post (singular, initial Cap.)
    3. Right-click Rubyweblog in the tree
      1. Run/Debug rake task
      2. db:create
    4. Right-click Rubyweblog in the tree
      1. Migrate Database
      2. To Current Version
    5. Open rubyweblog/Configuration/routes.rb
      1. Add   map.root :controller => "posts"    somewhere inside the do.
    6. Delete K:\NetBeansProjects\rubyweblog\public\index.html
    7. Right-click rubyweblog and select Run.
    8. Open a web browser to http://localhost:3000/ and create a couple of posts.
    9. Right-click Database Migrations, and select Generate (Generator = migration; Arguments = “AddBodyToPost body:text”)
    10. Right-click Rubyweblog in the tree
      1. Migrate Database
      2. To Current Version
    11. Edit rubyweblog\views\posts\edit.html.erb, and add a “<p>” for the body, similar to the title.
    12. Edit rubyweblog\views\posts\new.html.erb, and add a “<p>” for the body, similar to the title.
    13. Edit rubyweblog\views\posts\show.html.erb and make it look like:
      <p>
        <b>Title:</b>
        <%=h @post.title %>
      </p>
      
      <p>
        <b>Body:</b>
        <%=h @post.body %>
      </p>
      
      <%= link_to 'Edit', edit_post_path(@post) %> |
      <%= link_to 'Back', posts_path %>
    14. Use your browser to edit the posts and add bodies.

Let’s add Clearance authentication:

 

In config/environment.rb:

config.gem "thoughtbot-clearance", 
  :lib     => 'clearance', 
  :source  => 'http://gems.github.com', 
  :version => '>= 0.5.3'

In config/environments/test.rb:

config.gem 'thoughtbot-shoulda',
  :lib     => 'shoulda',
  :source  => "http://gems.github.com", 
  :version => '2.10.0'
config.gem 'thoughtbot-factory_girl',
  :lib     => 'factory_girl',
  :source  => "http://gems.github.com", 
  :version => '>= 1.2.0'

Then:

rake gems:install
rake gems:unpack 
rake gems:install RAILS_ENV=test
rake gems:unpack  RAILS_ENV=test
ruby script/generate clearance

Define a HOST constant in your environments files. In config/environments/test.rb and config/environments/development.rb it can be:

HOST = "localhost"

In production.rb it must be the actual host your application is deployed to. The constant is used by mailers to generate URLs in emails.

In config/environment.rb (outside the ‘do’):

DO_NOT_REPLY = donotreply@dialectic.us

Migrate Database / to current version

Add this to posts_controller.rb

  before_filter :authenticate, :except => [:index, :show]

Confirm that you can view posts but not create them without logging in

To logout enter http://localhost:3000/sessions/destroy

If you put “map.logout    '/logout',    :controller => 'sessions',  :action => 'destroy' ” into routes.rb, you can logout with http://localhost:3000/logout

These are some handy routes:

map.register  '/register',  :controller => 'users',     :action => 'new'
map.login     '/login',     :controller => 'sessions',  :action => 'new'
map.logout    '/logout',    :controller => 'sessions',  :action => 'destroy'