I have a single table that two people enter data into. Person A creates
the record and I need to specify certain required fields in his form.
Person B has a separate form and she fills in additional fields and I
need to specify that some of these are required.
Since the data is all in one table and since the validations are in the
model, won’t Rails complain when person A tries to save? I was getting
ready to see what would happen, but I thought I’d ask first. Thanks for
the help!
If I understand you correctly, there is one table with two distinct
types.
You could split this into two tables or use Single Table Inheritance.
If
you use STI, you would put a type field in the table and then have 3
models:
BaseClass
PersonA < BaseClass
PersonB < BaseClass
Then the PersonA model and PersonB model would have their own
validation,
with the common validations in the BaseClass.
Then the PersonA model and PersonB model would have their own
validation,
with the common validations in the BaseClass.
Hope this helps,
Ben
He’s an example: When we get a trouble call, the receptionist initiates
a ticket. There are certain fields that are mandatory (name, phone,
etc.) and certain fields that are optional (title, middle name, etc.).
Later, someone else opens the ticket, but with a totally different form
that has many additional fields from the table. Again, some of these
fields are required and some are optional.
I tried the two table approach and it introduced some unpleasant
complexities. I will look into single-table inheritance. Thanks!
you have :on => :save (which is the default) or :on => :create or :on
=> :update
it might fit with the flow you’ve described.
HTH
Trevor
Perfect! This is a simple solution to my problem. Man, I gotta get
better at asking questions, because as I think through your answer, and
my problem, I think during :create is the only time we’ll be dealing
with a partial form.
Again, some of these fields are required and some are optional.
You might also be interested in the :if parameter which allows you to
specify a method, proc or string to call to determine if the
validation should occur.
My example may have been a little misleading tho. In your scenario it’s
likely that your going to have the create-only validations have
no :on parameter
and the update-only validations will specify :on => :update.
Kinda backwards from my original example.
Trev
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.