This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
ROLES = [ | |
'admin', | |
'manager', | |
'branch_manager', | |
'planner', | |
'employee', | |
'customer' | |
].freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
composed_of :roles, :class_name => 'Array', | |
:mapping => %w(roles to_json), | |
:constructor => Proc.new { |roles| roles.nil? ? [] : JSON.parse(roles) }, | |
:converter => Proc.new { |roles| roles.class == Array ? roles : [] } | |
ROLES = [ | |
'admin', | |
'manager', | |
'branch_manager', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Registration < ActiveRecord::Base | |
# Database Relationships | |
belongs_to :person | |
belongs_to :event | |
# Validations | |
validates_presence_of :event_id | |
validates_presence_of :person_id | |
validates_uniqueness_of :person_id, :scope => :event_id, :message => "is already signed in or registered." | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@user = User.find(params[:responsibility][:user_id]) | |
@company = Company.find(params[:company_id]) | |
# create an array of responsibilities that we want to save | |
responsibilities = params[:responsibility][:division_ids].collect do |division_id| | |
Responsibility.new(:division_id => division_id, :user_id => @user.id) | |
end | |
# get a list of invalid responsibilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@user = User.find(params[:responsibility][:user_id]) | |
@company = Company.find(params[:company_id]) | |
# create an array of responsibilities that we want to save | |
responsibilities = params[:responsibility][:division_ids].collect do |division_id| | |
Responsibility.new(:division_id => division_id, :user_id => @user.id) | |
end | |
# get a list of invalid responsibilities |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sign_in_and_redirect(resource_or_scope, resource=nil, skip=false) | |
scope = Devise::Mapping.find_scope!(resource_or_scope) | |
resource ||= resource_or_scope | |
sign_in(scope, resource) unless skip | |
if current_user && current_user.is_customer_contact? | |
session[:customer_id] = current_user.customers.first.id | |
end | |
redirect_to :controller => 'dashboard', :locale => (current_user && current_user.language.to_s != "" ? current_user.language : I18n.locale) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ROLES = [ | |
'admin', | |
'manager', | |
'branch_manager', | |
'planner', | |
'employee', | |
'customer' | |
].freeze | |
# Define a method for each role: user.admin?, user.manager?, ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Include this module in your ActiveRecord model to gain a filter scope | |
# Filter applies the supplied query to given attributes (or all attributes if none are given) | |
# | |
# example: | |
# | |
# User.filter('Bob', [:first_name, :last_name]) | |
# | |
# returns all users with 'bob' in their first or last name | |
module Lico | |
module FilterScope |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def initialize(user) | |
if !user.nil? && !user.role.nil? | |
# internal employee | |
if user.company_id == 1 | |
can :manage, :all | |
# consumer | |
else | |
user.permissions.each do |permission| | |
if permission.is_internal? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<tbody> | |
<% products.each do |product| %> | |
<tr> | |
<td><%= link_to product.name, product %></td> | |
<td><%= truncate(strip_tags(product.description), :length => 80) %></td> | |
<td><%= product.price %></td> | |
</tr> | |
<% end %> | |
</tbody> |
OlderNewer