Skip to content

Instantly share code, notes, and snippets.

@StasKoval
Created June 20, 2014 11:56
Show Gist options
  • Save StasKoval/bbeab59e7b79ec75873f to your computer and use it in GitHub Desktop.
Save StasKoval/bbeab59e7b79ec75873f to your computer and use it in GitHub Desktop.
class Permission < ActiveRecord::Base
extend Enumerize
belongs_to :model_list
belongs_to :role
#belongs_to :user,:inverse_of => :permissions
serialize :fields, Array
def some_attribute
if self.model_list.present?
self.model_list.name.constantize.column_names.map{|c| c.to_s.split("_id").first}
#binding.pry
else
["first default"]
end
end
attr_accessible :action, :role_id, :model_list_id , :user_id, :fields#, :some_attribute
#attr_accessor :some_attribute
enumerize :action, in: [:show, :edit]
rails_admin do
edit do
configure :fields, :enum do
#binding.pry
enum_method do
:some_attribute
end
enum do
#binding.pry
bindings[:object].model_list.name.constantize.column_names.map{|c| c.to_s.split("_id").first} #if bindings[:object].model_list.present?
end
pretty_value do
bindings[:object].send(:some_attribute).map{|v| v.to_s.humanize.titleize }.join(', ') #if bindings[:object].model_list.present?
end
def form_value
bindings[:object].send(:some_attribute) #if bindings[:object].model_list.present?
end
# set this to true for multi-select
multiple do
true
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment