(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
- 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:…”
- It gave an error installing the doc, but the rest appears OK.
- gem install rails
- Start NetBeans
- File/New Project
- Ruby
- Ruby on Rails Application
- Project Name = rubyweblog
- Location=K:\NetBeansProjects
- Platform=Ruby 1.8.6-p287
- Server=WebRick
- Database Adapter=mysql
- database name = rubyweblog_development
- user=root
- Rails Version=2.3.2
- Right-click Rubyweblog in the tree
- Generate / Scaffold
- Model Name = Post (singular, initial Cap.)
- Right-click Rubyweblog in the tree
- Run/Debug rake task
- db:create
- Right-click Rubyweblog in the tree
- Migrate Database
- To Current Version
- Open rubyweblog/Configuration/routes.rb
- Add map.root :controller => "posts" somewhere inside the do.
- Delete K:\NetBeansProjects\rubyweblog\public\index.html
- Right-click rubyweblog and select Run.
- Open a web browser to http://localhost:3000/ and create a couple of posts.
- Right-click Database Migrations, and select Generate (Generator = migration; Arguments = “
AddBodyToPost body:text
”) - Right-click Rubyweblog in the tree
- Migrate Database
- To Current Version
- Edit rubyweblog\views\posts\edit.html.erb, and add a “<p>” for the body, similar to the title.
- Edit rubyweblog\views\posts\new.html.erb, and add a “<p>” for the body, similar to the title.
- 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 %>
- Use your browser to edit the posts and add bodies.
- File/New Project
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'