Topic: Active Scaffold

Hi everyone.

I'm an experienced programmer but a Ruby and Rails virgin. I like the look of Rails (having spent several years of misery developing web apps in PHP). In particular I like the initial look of Active Scaffold and got stuff working very quickly.
But there is a dearth of tutorials to get you past the beginner stage.

In particular, I am at my wits end trying to get the ActiveRecord validation methods (e.g. validates_length_of :name, :maximum=>40) passed into the app using ActiveScaffold.
If I put the statement into the UsersController class it is rejected as an unknown method.
If I put it into the model User<ActiveRecord class, it is accepted but ignored. (I think that ActiveScaffold builds its own model on the fly).

Can anyone help?

John O'Gorman

Re: Active Scaffold

If you look inside the ActiveRecord module:

module ActiveRecord
autoload :Base, 'active_record/base'
autoload :Batches, 'active_record/batches'
autoload :Calculations, 'active_record/calculations'
autoload :Callbacks, 'active_record/callbacks'
# ...
autoload :Timestamp, 'active_record/timestamp'
autoload :Transactions, 'active_record/transactions'
autoload :Validations, 'active_record/validations'
# ...
end

what means that all the validations happen on the level of Activerecord, and you should put validation callbacks in your model class which is a subclass of ActiveRecord::Base and not in a controller class which is a subclass of ApplicationController. As you see, it autoloads a Validation module which is responsible for validations.

Last edited by Javix (2011-06-06 11:11:19)