Displaying 1 result from an estimated 1 matches for "no_duplicate_nam".
Did you mean:
no_duplicate_names
2006 May 26
3
Breakdowns in has_many abstraction
...eb 2.0 app, Rain''d.
:-) The umbrellas are all named, and we want to make sure that each
person has uniquely-named umbrellas.
class Person < ActiveRecord::Base
has_many :umbrellas
def validate
errors.add("umbrellas", "must be uniquely named") unless
no_duplicate_names?
end
def no_duplicate_names?
names = umbrellas.collect {|u| u.name}
names.length == names.uniq.length
end
end
class Umbrella < ActiveRecord::Base
belongs_to :person
end
In people_controller.rb (note the comment in the middle):
def update
@person = Pe...