Skip to content

Instantly share code, notes, and snippets.

View baileylo's full-sized avatar

Logan Bailey baileylo

View GitHub Profile
<%= form_for(@user) do |f| %>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
def create
@user = User.new(params[:user])
respond_to do |format|
if @user.save
format.html { redirect_to(:users, :notice => 'Registration successfull.') }
format.xml { render :xml => @user, :status => :created, :location => @user }
else
format.html { render :action => "new" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
class UserSession < Authlogic::Session::Base
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
def persisted?
false
end
end
class UserSessionsController < ApplicationController
# GET /user_sessions/new
# GET /user_sessions/new.xml
def new
@user_session = UserSession.new
respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @user_session }
LoginApp::Application.routes.draw do
resources :users, :user_sessions
match 'login' => 'user_sessions#new', :as => :login
match 'logout' => 'user_sessions#destroy', :as => :logout
end
<body>
<div id="nav">
<%= link_to "Register", new_user_path%> |
<%= link_to "Login", :login %>
</div>
<%= yield %>
<h1>Listing users</h1>
<p id="notice"><%= notice %></p>
<table>
<tr>
<th>Username</th>
<th>Email</th>
<th></th>
<th></th>
<th></th>
</tr>
<div id="nav">
<% if current_user %>
<%= link_to "Edit Profile", edit_user_path(current_user.id)%>
<%= link_to "Logout", :logout%>
<% else %>
<%= link_to "Register", new_user_path%> |
<%= link_to "Login", :login %>
<% end %>
</div>
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :current_user
private
def current_user_session
return @current_user_session if defined?(@current_user_session)
@current_user_session = UserSession.find
class ConversationsController < ApplicationController
# GET /conversations
# GET /conversations.xml
def index
@conversations = Conversation.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @conversations }
end