Sha256: 3a35eddec2b8d0668b0657e66688da6fa829ce4572c083385725f807f9e50342

Contents?: true

Size: 653 Bytes

Versions: 13

Compression:

Stored size: 653 Bytes

Contents

module C80NewsTz
  class RubricValidator < ActiveModel::Validator
    def validate(record)
      puts '<RubricValidator.validate>'

      if record.title.blank?
        record.errors[:title] = 'Укажите, пожалуйста, название рубрики'
      else
        may_be_pages = Rubric.where(:title => record.title)
        # Rails.logger.info("<RubricValidator.validate> #{may_be_pages[0].id} vs #{record.id}")
        if may_be_pages.count > 0 && may_be_pages[0].id != record.id
          record.errors[:title] = 'Рубрика с таким названием уже существует'
        end
      end

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
c80_news_tz-0.1.1.26 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.25 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.24 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.23 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.22 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.21 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.19 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.18 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.17 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.16 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.15 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.1 app/models/c80_news_tz/rubric_validator.rb
c80_news_tz-0.1.1.0 app/models/c80_news_tz/rubric_validator.rb