(Much content based on http://www.netbeans.org/kb/docs/ruby/rapid-ruby-weblog.html)
AddBodyToPost body:text”) <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 %>
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=testruby script/generate clearanceDefine 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.usMigrate 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'
Add new comment