Class: ProfileField
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProfileField
- Extended by:
- ProfileFieldMixins::HasChildProfileFields
- Includes:
- ProfileFieldMixins::HasChildProfileFields
- Defined in:
- app/models/profile_field.rb
Direct Known Subclasses
ProfileFieldTypes::About, ProfileFieldTypes::AcademicDegree, ProfileFieldTypes::Address, ProfileFieldTypes::BankAccount, ProfileFieldTypes::Competence, ProfileFieldTypes::Custom, ProfileFieldTypes::Date, ProfileFieldTypes::Description, ProfileFieldTypes::Email, ProfileFieldTypes::Employment, ProfileFieldTypes::General, ProfileFieldTypes::Homepage, ProfileFieldTypes::NameSurrounding, ProfileFieldTypes::Organization, ProfileFieldTypes::Phone, ProfileFieldTypes::ProfessionalCategory, ProfileFieldTypes::Study
Class Method Summary collapse
-
.possible_types ⇒ Object
List all possible types.
Instance Method Summary collapse
- #children_count ⇒ Object
- #delete_cache ⇒ Object
-
#display_html ⇒ Object
Often, profile_fields are to be displayed in a certain manner on a HTML page.
-
#key ⇒ Object
This method returns the key, i.e.
-
#label ⇒ Object
This method returns the label text of the profile_field.
-
#orig_profileable ⇒ Object
For child profile fields, this returns the profileable of the parent.
- #profileable ⇒ Object
-
#save(*args) ⇒ Object
Overwrite save to ensure that the cache is deleted in case of changes.
-
#underscored_type ⇒ Object
Returns a profile field type in an underscored form that can be used as argument for I18n.translate.
-
#value ⇒ Object
If the field has children, their values are included in the main field’s value.
Methods inherited from ActiveRecord::Base
Class Method Details
.possible_types ⇒ Object
List all possible types. This is needed for code injection security checks.
175 176 177 178 179 180 181 182 183 184 185 |
# File 'app/models/profile_field.rb', line 175 def self.possible_types [ProfileFieldTypes::General, ProfileFieldTypes::Custom, ProfileFieldTypes::Organization, ProfileFieldTypes::Email, ProfileFieldTypes::Address, ProfileFieldTypes::About, ProfileFieldTypes::Employment, ProfileFieldTypes::ProfessionalCategory, ProfileFieldTypes::Competence, ProfileFieldTypes::BankAccount, ProfileFieldTypes::Description, ProfileFieldTypes::Phone, ProfileFieldTypes::NameSurrounding, ProfileFieldTypes::Homepage, ProfileFieldTypes::Date, ProfileFieldTypes::AcademicDegree ] end |
Instance Method Details
#children_count ⇒ Object
104 105 106 |
# File 'app/models/profile_field.rb', line 104 def children_count children.count end |
#delete_cache ⇒ Object
98 99 100 101 102 |
# File 'app/models/profile_field.rb', line 98 def delete_cache super parent.try(:delete_cache) profileable.delete_cache if profileable && profileable.respond_to?(:delete_cache) end |
#display_html ⇒ Object
Often, profile_fields are to be displayed in a certain manner on a HTML page. This method returns the profile_field’s value as HTML code in the way the profile_field should be displayed.
Override this in the inheriting classes in ordner to modify the html output of the value.
56 57 58 59 60 61 62 |
# File 'app/models/profile_field.rb', line 56 def display_html if self.value.try(:include?, "\n") BestInPlace::ViewHelpers.markup(self.value) else self.value end end |
#key ⇒ Object
This method returns the key, i.e. the un-translated label, which is needed for child profile fields.
67 68 69 |
# File 'app/models/profile_field.rb', line 67 def key read_attribute :label end |
#label ⇒ Object
This method returns the label text of the profile_field. If a translation exists, the translation is returned instead.
74 75 76 77 78 |
# File 'app/models/profile_field.rb', line 74 def label label_text = super label_text = self.underscored_type if not label_text.present? translated_label_text = I18n.translate( label_text, :default => label_text.to_s ) if label_text.present? end |
#orig_profileable ⇒ Object
For child profile fields, this returns the profileable of the parent. For parents, this returns just the assigned profileable.
This has to be here, since child profile fields do not have the ‘has_child_profile_fields` call in their classes.
145 |
# File 'app/models/profile_field.rb', line 145 alias_method :orig_profileable, :profileable |
#profileable ⇒ Object
146 147 148 149 150 151 152 |
# File 'app/models/profile_field.rb', line 146 def profileable if parent.present? parent.profileable else orig_profileable end end |
#save(*args) ⇒ Object
Overwrite save to ensure that the cache is deleted in case of changes.
93 94 95 96 |
# File 'app/models/profile_field.rb', line 93 def save( *args ) delete_cache super( *args ) end |
#underscored_type ⇒ Object
Returns a profile field type in an underscored form that can be used as argument for I18n.translate. Example: For a ProfileFieldTypes::FooBar-type profile field, this method returns ‘foo_bar’.
111 112 113 |
# File 'app/models/profile_field.rb', line 111 def underscored_type self.type.demodulize.underscore end |
#value ⇒ Object
If the field has children, their values are included in the main field’s value. Attention! Probably, you want to display only one in the view: The main value or the child fields.
83 84 85 86 87 88 89 |
# File 'app/models/profile_field.rb', line 83 def value if children_count > 0 ( [ super ] + children.collect { |child| child.value } ).join(", ") else super end end |