Module: PermissionsHelper

Defined in:
lib/permissions_helper.rb

Instance Method Summary collapse

Instance Method Details

#permission_fields(object_name, actions = []) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/permissions_helper.rb', line 2

def permission_fields(object_name, actions = [])
  actions = %w[index show new create edit update destroy] if actions.empty?
  actions.delete('create') if actions.include?('new')
  actions.delete('update') if actions.include?('edit')
  (:fieldset, :id => "#{object_name}_permissions") do
    (:legend, "Permissions") +
    actions.collect do |action|
      (:p) do
        label(object_name, "#{action}_permission", action.to_s.humanize) +
        tag('br') + "\n" +
        select(object_name, "#{action}_permission", [ ["allow", true], ["deny", false] ], {:include_blank => 'ignore'})
      end
    end.join("\n")
  end
end