Robs Reminders r3 – Authentication and Base model

r3 available via is now up and running at .

In this check-in I installed the authentication system, created the reminder model, added a site wide layout, and created a main controller. Wow! Most updates won’t be this big. Also the contents of this entry are very similar to my previous tutorial on act_as_authenticated.

The first step of course is to build the database and create authentication.

rake db:create

(Note: I had to change the socket: in config/database.yml on my ubuntu machine, I did this by generating a separate app and coping the config information.)

script/plugin install

ruby script/generate authenticated user account

rake db:migrate

Add the AuthenticatedSystem to /app/controllers/application.rb

class ApplicationController < ActionController::Base helper :all # include all helpers, all the time
include AuthenticatedSystem

The primary model for this application is the Reminder. Now I don’t have a complete design for the application, but this is what I have so far.

Reminder has title, body, due, complete.

script/generate scaffold Reminder title:string body:text done:boolean due:datetime

and of course tied to a user_id

script/generate migration add_user_id_to_reminder

class AddUserIdToReminder < ActiveRecord::Migration def self.up
add_column :reminders, :user_id, :integer

def self.down
remove_column :reminders, :user_id

add the one to many relation between reminder and user

has_may :reminders

belongs_to :user

Create a main controller, this will serve as the root of the application. With and index method, and an index view.

Map the main controller to the root. routes.rb

map.root :controller => “main”

define an application wide template containing a login tool-bar.


<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”

<html xmlns=”” xml:lang=”en” lang=”en”>
<meta http-equiv=”content-type” content=”text/html;charset=UTF-8″ />
<title>Reminders: <%= controller.action_name %></title>
<%= stylesheet_link_tag ‘scaffold’ %>

<div style=”border-bottom:solid 1px black;”>

Robs Reminders
<span style=”float:right;”>
<% if current_user == :false %>
<%= link_to “Login”, {:controller => ‘account’, :action => ‘login’}%>
<%= link_to “Signup”, {:controller => ‘account’, :action => ‘signup’}%>
<% else %>
<%= current_user.login %>
<%= link_to “Logout”, {:controller => ‘account’, :action => ‘logout’}%>
<%= link_to “Edit URL”, {:controller => ‘main’, :action => ‘edit’}%>
<%= link_to “Reminders”, {:controller => ‘reminders’, :action => ‘index’}%>
<% end%>
<p style=”color: green”><%= flash[:notice] %></p>
<%= yield %>


delete the index.html page

Delete all other layout files

Modify the account controller to redirect to the main page.

Modify the reminders controller to user the current_user for loading and saving reminders. (as seen in the authentication tutorial. )
This takes us to SVN r3.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *