found another prettier way

pull/859/head
Jonas Heinrich 11 years ago
parent 5ce30b12b7
commit 06f2b8b8bf
  1. 12
      app/models/group.rb
  2. 7
      config/initializers/10-patches.rb

@ -37,11 +37,13 @@ class Group < Principal
acts_as_customizable acts_as_customizable
validates_presence_of :lastname
validates_uniqueness_of :lastname, :case_sensitive => false
validates_length_of :lastname, :maximum => 30
before_destroy :remove_references_before_destroy before_destroy :remove_references_before_destroy
alias_attribute(:groupname, :lastname)
validates_presence_of :groupname
validate :uniqueness_of_groupname
validates_length_of :groupname, :maximum => 30
def to_s def to_s
lastname.to_s lastname.to_s
@ -106,4 +108,8 @@ class Group < Principal
Journal::WorkPackageJournal.update_all({ :assigned_to_id => deleted_user.id }, Journal::WorkPackageJournal.update_all({ :assigned_to_id => deleted_user.id },
{ :assigned_to_id => id }) { :assigned_to_id => id })
end end
def uniqueness_of_groupname
errors.add :groupname, :taken if Group.find_by_lastname(lastname)
end
end end

@ -75,13 +75,6 @@ module ActiveModel
}) })
end end
end end
elsif attribute == :lastname && @base.class.to_s == 'Group'
attr_name = @base.class.human_attribute_name(:groupname, :default => 'Groupname')
full_messages << I18n.t(:"errors.format", {
:default => "%{attribute} %{message}",
:attribute => attr_name,
:message => message
})
else else
attr_name = attribute.to_s.gsub('.', '_').humanize attr_name = attribute.to_s.gsub('.', '_').humanize
attr_name = @base.class.human_attribute_name(attribute, :default => attr_name) attr_name = @base.class.human_attribute_name(attribute, :default => attr_name)

Loading…
Cancel
Save