Sha256: 383cc5bbf5e7b12bde90c07982f061358d121d68eae55e97163c0c27d1d932b8

Contents?: true

Size: 756 Bytes

Versions: 4

Compression:

Stored size: 756 Bytes

Contents

module Blacksand
  class Navigation < ActiveRecord::Base
    belongs_to :page

    # ActiveRecord attribute api changed, see http://api.rubyonrails.org/classes/ActiveRecord/Attributes/ClassMethods.html#method-i-attribute
    if ActiveRecord::VERSION::MAJOR >= 5
      attribute :options, :json_type
    else
      attribute :options, MyJsonType.new
    end

    validates :name, presence: true
    validates :url, format: {with: URI.regexp}, if: Proc.new { |a| a.url.present? }

    validate :url_or_page_presence

    def url_or_page_presence
      if url.blank? && page_id.blank?
        errors.add(:url, "链接或者页面两个必须要填一项")
        errors.add(:page_id, "链接或者页面两个必须要填一项")
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacksand-2.4.1 app/models/blacksand/navigation.rb
blacksand-2.4.0 app/models/blacksand/navigation.rb
blacksand-2.3.0 app/models/blacksand/navigation.rb
blacksand-2.2.2.1 app/models/blacksand/navigation.rb