Intake forms

I’m building a system whereby each practitioner can customize their intake form. I’ll provide a wide range of sections that can be added/removed and re-ordered. This is obviously a bit of a challenge. I still haven’t figured out how I’ll handle validation, I’ll probably have to write something custom.

Today was a big push in that direction. I build a nice UI with jQuery drag and drop to re-order the modules. I still have to build the adding modules part, and saving the new order to the DB. I’ve laid the groundwork there though, by changing the model relationships. Initially Users had :has_and_belongs_to_many relationships with FormSections. But that didn’t let me save the order in which the FormSections were saved. So I fleshed out the FormSectionsUsers model to be fully fledged with id and order columns, and some indices. Then I changed the relationshop to :has_many, :through.

One thing that’s so easy to miss in the Guide is that you need :has_many definitions for both the target of the association, and for the association model itself. Don’t forget the asterisked lines below (from the Association Guide):

[ruby] class Physician
***has_many :appointments***
has_many :patients, :through => :appointments

class Appointment
belongs_to :physician
belongs_to :patient

class Patient
***has_many :appointments***
has_many :physicians, :through => :appointments

Comments are closed, but trackbacks and pingbacks are open.