Saturday, March 22, 2014

Collect funds for your group projects

I've been working on a project to help classrooms at my son's school collect funds for end of year gifts, team dues, etc. It's called Sidejar, and it's been working really well. It's motivating to hear the comments from the parents that would not have donated without a credit card interface.

"I love the convenience of this site. Thanks for coordinating and for the reminder!"

It's somewhat obvious, if you think about it, the more convenient it is to pay, the more people pay. It's been especially great to see it used by parents and teachers. It's a great cause to contribute too. Teachers give so much of their personal time and money, it's great for parents to have a chance to show their appreciation.

Sidejar - Money between Friends

Given a string to build a Rails object relationship

In situations where you want to take in a string - like when you are taking the results of an autocomplete, to form a relationship with another object - this is a pattern I like to use...

For example, say you wanted to credit an article to an author. There are many authors in the system, and their names are known. You might want to edit an article and change the name of the author...

In that situation, to build the relationship with the author (and set the foreign key), it takes a little effort to find the author by name, if he's not there, create a new author using the entered name.

attr_accessible :body, :title, :author_name
attr_accessor :body, :title, :author_name

before_validation :set_author
after_initialize :set_author_name

def set_author_name
  self.author_name ||= author.try(:name)

def set_author = Author.where(:name => author_name).first_or_initialize