Class: PermissionsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/permissify/controller/template/permissions_controller.rb

Direct Known Subclasses

ProductsController

Instance Method Summary collapse

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 24

def create
  @permissions_object = @permissions_class.new
  @permissions_object.name = params[@corresponding_class_params_key][:name]
  @permissions_object.from = params[@corresponding_class_params_key][:from]
  @permissions_object.save
  set_permissions_object
  @response_message = @permissions_object.errors.full_messages.join(', ')
  js_response
end

#destroyObject



15
16
17
18
19
20
21
22
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 15

def destroy
  if @permissions_object.respond_to?(:deleted_at)
    @permissions_object.update_attribute(:deleted_at, Time.now)
  else
    @permissions_object.destroy
  end
  js_response
end

#editObject



11
12
13
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 11

def edit
  js_response
end

#find_permissions_objectObject



63
64
65
66
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 63

def find_permissions_object
  @permissions_object = @permissions_class.find(params[:id])
  set_permissions_object
end

#indexObject



7
8
9
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 7

def index
  render :template => 'permissions/index'
end

#js_responseObject



68
69
70
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 68

def js_response
  render :action => "#{@view_directory}#{params[:action]}_response"
end

#set_navObject



72
73
74
75
76
77
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 72

def set_nav
  @active_tab = 'admin'
  @active_section = 'Admin'
  @active_nav = @permissions_header
  @current_entity = @entity = Admin.first
end

#set_the_permissions_class(the_class, corresponding_class_params_key, prefix, applicability, permissions_header, sort_field = :name) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 49

def set_the_permissions_class(the_class, corresponding_class_params_key, prefix, applicability, permissions_header, sort_field = :name)
  @permissions_prefix = prefix
  @permissions_class  = the_class
  @corresponding_class_params_key = corresponding_class_params_key
  @applicability = applicability
  # relative pathing isn't working in devint (ok in dev): working around with post-deploy symlinks
  @view_directory = Rails.env == 'development' ? '../permissions/' : ''
  @permissions_name = @permissions_prefix.chop
  @permissions_category = @permissions_name+'s'
  @sort_field = sort_field
  @index_columns = corresponding_class_params_key == :role ? 6 : 4
  @permissions_header = permissions_header
end

#updateObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/permissify/controller/template/permissions_controller.rb', line 34

def update
  permission_attributes = params[@permissions_name]
  permission_attributes ||= {}
  class_attributes = params[@corresponding_class_params_key]
  class_attributes ||= {}
  # @saved = @permissions_object.update_attributes class_attributes.merge(permission_attributes)
  attrs = class_attributes.merge(permission_attributes)
  @permissions_object.name = attrs[:name]
  @permissions_object.permissions = attrs[:permissions]
  set_permissions_object_specific_values(attrs)
  # @permissions_object.attributes = class_attributes.merge(permission_attributes)
  @saved = @permissions_object.save
  js_response
end