aboutsummaryrefslogtreecommitdiffstats
path: root/app/models/about_me_validator.rb
blob: 8c24cfd67ddbdbc6b3a5fbc47278d8c92e58004c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# models/about_me_validator.rb:
# Validates editing about me text on user profile pages.
#
# Copyright (c) 2010 UK Citizens Online Democracy. All rights reserved.
# Email: hello@mysociety.org; WWW: http://www.mysociety.org/

class AboutMeValidator
    include ActiveModel::Validations

    attr_accessor :about_me

    # TODO: Switch to built in validations
    validate :length_of_about_me

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

    private

    def length_of_about_me
        if !about_me.blank? && about_me.size > 500
            errors.add(:about_me, _("Please keep it shorter than 500 characters"))
        end
    end
end