Without seeing your model structure, this is just speculation, but here goes:
--
Virtual Attributes
In your User
model, you can use attr_accessor
to create a set of virtual attributes
- which basically mean you can create a series of setter / getter
methods in your User
model.
Although I don't think this will help you directly, it should give you an idea as to how you can create single-model validation:
#app/models/user.rb
Class User < ActiveRecord::Base
attr_accessor :new, :values, :to, :validate
validates, :new, :values, :to, :validate, presence: true
end
This will allow you to create the attributes in the User
model - and although they won't be saved, you can then use them to validate against
attr_accessor
To give you a quick overview of this method, you first need to remember that Rails is just a collection of modules
and classes
.
This means that every model
you load is just a class
which has been populated with a series of getter
/ setter
methods. These methods are defined by ActiveRecord
from your data table columns, and are why you can call @user.attribute
The magic is that if you use attr_accessor
, you'll basically create your own attributes in your User
model - which won't be saved in the database, but will be treated like the other attributes your objects have, allowing you to validate them