Got abilities working on index; next need to separate users from members from cards.
This commit is contained in:
parent
0bc5858101
commit
93e77b692f
2
Gemfile
2
Gemfile
@ -28,7 +28,7 @@ gem 'devise'
|
|||||||
gem "cancan"
|
gem "cancan"
|
||||||
|
|
||||||
# To use ActiveModel has_secure_password
|
# To use ActiveModel has_secure_password
|
||||||
# gem 'bcrypt-ruby', '~> 3.0.0'
|
gem 'bcrypt-ruby', '~> 3.0.0'
|
||||||
|
|
||||||
# To use Jbuilder templates for JSON
|
# To use Jbuilder templates for JSON
|
||||||
# gem 'jbuilder'
|
# gem 'jbuilder'
|
||||||
|
@ -29,6 +29,7 @@ GEM
|
|||||||
i18n (~> 0.6)
|
i18n (~> 0.6)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
arel (3.0.2)
|
arel (3.0.2)
|
||||||
|
bcrypt-ruby (3.0.1)
|
||||||
builder (3.0.0)
|
builder (3.0.0)
|
||||||
cancan (1.6.8)
|
cancan (1.6.8)
|
||||||
coffee-rails (3.2.2)
|
coffee-rails (3.2.2)
|
||||||
@ -115,6 +116,7 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
bcrypt-ruby (~> 3.0.0)
|
||||||
cancan
|
cancan
|
||||||
coffee-rails (~> 3.2.1)
|
coffee-rails (~> 3.2.1)
|
||||||
devise
|
devise
|
||||||
|
@ -7,7 +7,7 @@ class UsersController < ApplicationController
|
|||||||
def index
|
def index
|
||||||
#@users = User.all
|
#@users = User.all
|
||||||
#authorize! :read, @users
|
#authorize! :read, @users
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html # index.html.erb
|
format.html # index.html.erb
|
||||||
format.json { render :json => @users }
|
format.json { render :json => @users }
|
||||||
|
@ -2,13 +2,13 @@ class Ability
|
|||||||
include CanCan::Ability
|
include CanCan::Ability
|
||||||
|
|
||||||
def initialize(user)
|
def initialize(user)
|
||||||
if user.admin?
|
if !user.nil?
|
||||||
can :manage, :all
|
if user.admin?
|
||||||
else
|
can :manage, :all
|
||||||
can :read, User do |u|
|
else
|
||||||
u.id == user.id
|
can :read, User, :id => user.id
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
# Define abilities for the passed in user here. For example:
|
# Define abilities for the passed in user here. For example:
|
||||||
#
|
#
|
||||||
# user ||= User.new # guest user (not logged in)
|
# user ||= User.new # guest user (not logged in)
|
||||||
|
@ -8,10 +8,12 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<a href="/users">Users</a>
|
<%= link_to 'Users', users_path if user_signed_in? %>
|
||||||
<a href="/door_logs">Logs</a>
|
<%= link_to 'Logs', door_logs_path if user_signed_in? %>
|
||||||
<%= link_to 'Profile', edit_user_registration_path if user_signed_in? %>
|
<%= link_to 'Profile', edit_user_registration_path if user_signed_in? %>
|
||||||
<%= link_to 'Sign out', destroy_user_session_path, :method => :delete if user_signed_in? %>
|
<%= link_to 'Sign out', destroy_user_session_path, :method => :delete if user_signed_in? %>
|
||||||
|
<%= link_to 'Sign in', new_user_session_path unless user_signed_in? %>
|
||||||
|
<%= link_to 'Sign up', new_user_registration_path unless user_signed_in? %>
|
||||||
</div>
|
</div>
|
||||||
<p class="notice"><%= notice %></p>
|
<p class="notice"><%= notice %></p>
|
||||||
<p class="alert"><%= alert %></p>
|
<p class="alert"><%= alert %></p>
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
<th></th>
|
<th></th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<% @users.each do |user| %>
|
<% if !@users.blank? %>
|
||||||
|
<% @users.each do |user| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= user.name %></td>
|
<td><%= user.name %></td>
|
||||||
<td><%= user.card_id %></td>
|
<td><%= user.card_id %></td>
|
||||||
@ -23,6 +24,7 @@
|
|||||||
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
<td><%= link_to 'Edit', edit_user_path(user) %></td>
|
||||||
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
<td><%= link_to 'Destroy', user, :confirm => 'Are you sure?', :method => :delete %></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
<html>
|
|
||||||
<head></head>
|
|
||||||
<body>
|
|
||||||
<a href="/users">Users</a>
|
|
||||||
<a href="/door_logs">Logs</a>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
Loading…
x
Reference in New Issue
Block a user