Skip to content

Instantly share code, notes, and snippets.

@antunderwood
Created June 9, 2009 16:29
Show Gist options
  • Save antunderwood/126616 to your computer and use it in GitHub Desktop.
Save antunderwood/126616 to your computer and use it in GitHub Desktop.
<%= form.error_messages %>
<div id="user_form">
<div class="text_field">
<%= form.label :email %>
<%= form.text_field :email %>
</div>
<div class="password_field">
<%= form.label :password %>
<%= form.password_field :password %>
</div>
<div class="password_field">
<%= form.label :password_confirmation, "Verify password" %>
<%= form.password_field :password_confirmation %>
</div>
<% if signed_in_as_admin? %>
<div class="select_field">
<%= form.select :role, Roleify::Role::ROLES %>
<%= form.label :role, "Role" %>
</div>
<% end %>
</div>
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
include Clearance::Authentication
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
# Scrub sensitive parameters from your log
filter_parameter_logging :password
helper_method :signed_in_as_admin?
def signed_in_as_admin?
signed_in? && current_user.admin?
end
def users_only
deny_access("Please Login or Create an Account to Access that Feature.") unless signed_in?
end
def admin_only
deny_access("Please Login as an administrator to Access that Feature.") unless signed_in_as_admin?
end
end
<h2>Edit User</h2>
<% form_for @user do |form| %>
<%= render :partial => '/users/form', :object => form %>
<%= form.submit 'Update user details', :disable_with => 'Please wait...' %>
<% end %>
<table>
<tr>
<th>Email</th>
<th>Confirmed Email?</th>
<th>Role</th>
<tr>
<% @users.each do |user| %>
<tr>
<td><%= link_to user.email, user_path(user) %></td>
<td><%= user.email_confirmed %></td>
<td><%= user.role %></td>
</tr>
<% end %>
</table>
<h3><%= mail_to @user.email if signed_in? %></h3>
<% if signed_in_as_admin? %>
<div id="control_block">
<%= link_to "Edit", edit_user_path(@user) %>
<%= link_to "Users", users_path %>
</div>
<% end %>
class User < ActiveRecord::Base
include Roleify::RoleifyableModel
include Clearance::User
end
class UsersController < Clearance::UsersController
before_filter :admin_only, :only => [ :index, :show ]
before_filter :users_only, :only => [ :edit, :update ]
def index
@users = User.find :all
end
def show
@user = User.find(params[:id])
end
def edit
if signed_in_as_admin?
@user = User.find(params[:id])
else
@user = current_user
end
end
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
flash[:notice] = 'User Record was successfully updated.'
format.html { redirect_to(user_url(@user)) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @user.errors, :status => :unprocessable_entity }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment