Users can now be saved with sub_roles
This commit is contained in:
1 parent
4108ebf06d
commit
afbffe37d5
16 files changed
+125
-88
No files matched your search
@@ -14,7 +14,7 @@ class AttributeField
|
||||
has_one :i18n_variable, :as => :language_value, :autosave => true, :dependent => :destroy
|
||||
has_many :attribute_values
|
||||
|
||||
validates_uniqueness_of :key
|
||||
# validates_uniqueness_of :key
|
||||
|
||||
# Convert the string list_options into an array
|
||||
def select_list_options=(var)
|
||||
|
||||
@@ -8,4 +8,8 @@ class AttributeValue
|
||||
belongs_to :attribute_field
|
||||
belongs_to :user
|
||||
|
||||
def method_missing(field)
|
||||
self[field]
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,7 +1,7 @@
|
||||
class SubRole < Attribute
|
||||
|
||||
belongs_to :role
|
||||
has_many :users
|
||||
has_and_belongs_to_many :users
|
||||
|
||||
# Get an sub_role from key
|
||||
def self.get_sub_role_from_key(key)
|
||||
|
||||
@@ -12,7 +12,7 @@ class User
|
||||
|
||||
has_many :attribute_values, :autosave => true, :dependent => :destroy
|
||||
belongs_to :role
|
||||
belongs_to :sub_role
|
||||
has_and_belongs_to_many :sub_roles
|
||||
accepts_nested_attributes_for :attribute_values, :allow_destroy => true
|
||||
|
||||
def name
|
||||
@@ -27,7 +27,13 @@ class User
|
||||
end
|
||||
|
||||
def get_attribute_values
|
||||
@attribute_values ||= self.attribute_values.to_a
|
||||
@attribute_values ||= self.attribute_values
|
||||
end
|
||||
|
||||
def get_value_from_field_id(field_id)
|
||||
values = get_attribute_values
|
||||
value = values.detect {|value| value.attribute_field_id == field_id} rescue nil
|
||||
value ? value : self.attribute_values.build
|
||||
end
|
||||
|
||||
end
|
||||
Reference in new issue
Block a user