Ruby On Rails Session Management Login And Comment Example

Login Management

Authenticating the User:
Setting the Session:
Checking Roles:
Invalidating Session:

Creating the Login page
Implementing the Authentication Method
Setting up the Session
Applying Authorization

Gathering User Comments

Adding a Comment:
Deleting a Comment:
Viewing Comments:

Creating the Tables

CREATE TABLE `comments` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`comment_body` TEXT NOT NULL ,
`submission_date` DATE NOT NULL ,
`tale_id` INT NOT NULL,
`user_id` INT NOT NULL,
CONSTRAINT `fk_comments_users` FOREIGN KEY (`user_id`) REFERENCES users( `id`) ,
CONSTRAINT `fk_comments_tales` FOREIGN KEY (`tale_id`) REFERENCES tales( `id`)
) ENGINE = innodb;

Creating the Login Page

# user_controller.rb
def index
end
<%= form_tag :action=> 'authenticate'%>
<table><table >
<tralign="center" class="tablebody"><tr align="tablebody">
<td>User name:</td>
<td><%= text_field("user", "user_name",:size=>"15" ) %></td>
</tr></tr>
<tr align="center" class="tablebody">
<td>Password:</td>
<td><%= password_field("user",
"password",:size=>"17" ) %></td>
</tr>
<tr align="center" class="tablebody">
<td></td>
<td><input type="submit" value=" LOGIN " /></td>
</tr></tr>
</table>