Prev | Current Page 203 | Next

Kevin Marshall, Chad Pytel, and Jon Yurek

"Pro Active Record: Databases with Ruby and Rails"

If other applications or programs, such as Java programs, access your database,
they would need to do their own data validations.
In the end, it??™s up to you, the developer, to choose where and how to implement your data
validations. My personal recommendation is that you centralize your validations within your
database via constraints and other database-specific features when more than one application
or program will be directly accessing your database??”especially if they all won??™t be written in
Ruby. But I also recommend adding Active Record validations to your models in all your Ruby
applications. It won??™t hurt your program and can only help to ensure that at least your Ruby applications
and programs are inserting and dealing with clean data.
OK, enough theory and design, let??™s get into the details of how Active Record validations
work and how to implement them within your models. Implementing Active Record data validations
is a very simple two-step process:
1. Add a protected validate method to your model.


Pages:
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215