Hey everyone, I’m just beginning rails (and this list) and I am
having a little trouble with something. I’m trying to make sure I
validate everything that needs to be validated, but I’m having a hard
time grasping how ActiveRecord handles validations. I have a schema
like this:
Account
- has_many Users
- has_one ServicePlan
I’ve included my code sample at the bottom of the email. Basically I
can do a ‘validates_presence_of :service_plan’ but I can’t figure out
how to ‘validates_numericality_of :service_plan’ or
‘validates_numericality_of :service_plan_id’ or anything. I BELIEVE
I understand that I should never have to access
Account.service_plan_id directly since I would always use
Account.service_plan.id, so is it correct that I dont have to
validate the type of the service plan Id? I just “trust” rails?
Also, as a side question, how does rails translate class names into
property names? I don’t quite grasp the naming convention. Is the
above correct in that the ServicePlan belonging to an Account object
is ‘MyAccount.service_plan’ and not ‘MyAccount.servicePlan’?
Sorry for the beginner questions. I guess I gotta start somewhere
right?
Code Sample:
class Account < ActiveRecord::Base
has_many :users
has_one :service_plan
validates_presence_of :name, :service_plan
validates_numericality_of :service_plan # ??? Does this need to
be validated?
end
Thanks,
Cliff