logo
Published on Input Jam (http://www.kleinfelter.com)

Rails on Windows April 2009

By Kevin Kleinfelter
Created 2009-04-12 22:07

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

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 [3]

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 [4]

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

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'

Source URL:
http://www.kleinfelter.com/node/163