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
-
#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.
170 171 172 173 174 175 176 177 178 179 180 |
# File 'app/models/profile_field.rb', line 170 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
99 100 101 |
# File 'app/models/profile_field.rb', line 99 def children_count children.count end |
#delete_cache ⇒ Object
93 94 95 96 97 |
# File 'app/models/profile_field.rb', line 93 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.
58 59 60 61 62 63 64 |
# File 'app/models/profile_field.rb', line 58 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.
69 70 71 |
# File 'app/models/profile_field.rb', line 69 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.
76 77 78 79 80 |
# File 'app/models/profile_field.rb', line 76 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.
140 |
# File 'app/models/profile_field.rb', line 140 alias_method :orig_profileable, :profileable |
#profileable ⇒ Object
141 142 143 144 145 146 147 |
# File 'app/models/profile_field.rb', line 141 def profileable if parent.present? parent.profileable else orig_profileable end 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’.
106 107 108 |
# File 'app/models/profile_field.rb', line 106 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.
85 86 87 88 89 90 91 |
# File 'app/models/profile_field.rb', line 85 def value if children_count > 0 ( [ super ] + children.collect { |child| child.value } ).join(", ") else super end end |