Sha256: 67b31add75cc6b73dfec89411a4453a6337a8b02c7d85514d39129b2dea06d8c

Contents?: true

Size: 1.07 KB

Versions: 30

Compression:

Stored size: 1.07 KB

Contents

class Contact
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  attr_accessor <%= fields.map{|e| ":#{e}" }.join(', ') -%>

<%- if fields.include?('email') -%>
  # validations for email
  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  validates_format_of :email, with: VALID_EMAIL_REGEX, message: "#{I18n.t('model.attributes.email')} #{I18n.t('activerecord.errors.messages.invalid')}"
  validates_presence_of :email, message: "#{I18n.t('model.attributes.email')} #{I18n.t('activerecord.errors.messages.blank')}"
  <%- fields.delete('email') -%>
<%- end -%>

<%- fields.each do |field| -%>
  # validations for <%= field %>
  validates_presence_of :<%= field -%>, message: "#{I18n.t('model.attributes.<%= field -%>')} #{I18n.t('activerecord.errors.messages.blank')}"

<%- end -%>

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def self.display_name
    'Mail'
  end

  def self.get_attribute_label(label)
    return label
  end

  def persisted?
    false
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
adminpanel-3.6.1 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.6.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.5.1 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.5.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.7 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.6 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.5 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.4 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.3 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.2 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.1 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.4.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.3.4 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.3.3 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.3.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.2.1 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.2.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.1.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-3.0.0 lib/generators/adminpanel/contact/templates/contact_template.rb
adminpanel-2.6.1 lib/generators/adminpanel/contact/templates/contact_template.rb