Nick Sutterer's Reform gem appears to be awesome but for some reason i cannot grok how to apply it to my proof-of-concept Rails app. I have read the docs and a number of blog posts but still do not fully understand how it would work.
Given the following criteria, what would the code for models, form object class, view and controller look like?
- The app has
User
andPet
models - The signup form accepts a
User.email
and hisPet.name
- Users cannot signup without a valid email address
- When a user signs up the
User
's account is created and apet
row is created and automatically associated to the user
Sample models:
A user
# app/models/user.rb
class User < ActiveRecord::Base
has_many :pets
end
His pet
# app/models/pet.rb
class Pet < ActiveRecord::Base
belongs_to :user
end
Thank you!
You then instantiate the form as follows.
And validation works vice-versa.
I recommend you buying the book. This is no covert advertise but I was basically repeating myself here hahaha.