Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module AssociateWithList
- def associate_with_list(column_name, list_name)
- define_method "#{column_name}_list" do
- items = AssociatedListItem.find(:all, :conditions => "list_name = '#{list_name}'").collect { |i| i.value.to_s }
- end
- define_method "add_#{column_name}_to_list" do
- value = self.send(column_name.to_sym)
- item = AssociatedListItem.find_or_create_by_list_name_and_value(list_name, value)
- end
- self.send("after_save :add_#{column_name}_to_list")
- end
- end
Add Comment
Please, Sign In to add comment