Guest User

Untitled

a guest
Apr 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. module AssociateWithList
  2. def associate_with_list(column_name, list_name)
  3. define_method "#{column_name}_list" do
  4. items = AssociatedListItem.find(:all, :conditions => "list_name = '#{list_name}'").collect { |i| i.value.to_s }
  5. end
  6.  
  7. define_method "add_#{column_name}_to_list" do
  8. value = self.send(column_name.to_sym)
  9. item = AssociatedListItem.find_or_create_by_list_name_and_value(list_name, value)
  10. end
  11.  
  12. eval "after_save add_#{column_name}_to_list"
  13. end
  14. end
Add Comment
Please, Sign In to add comment