We have created a FakeModel object class which inherits from Object, to allow working with models who don't have a DB table.
It has the basic functionality of a regular ActiveRecord model. We also a开发者_如何学JAVAdded in the class the following line:
include ActiveRecord::Validations
The problem is this: A new request is sent to the controller, and creates a new object inheriting from the FakeModel class. When the validations of that object run, they run more then once. Too be more specific - with each request sent to the server, the validations run one time more than the last request.
I'm guessing something here "sticks" on the server-level (of course, when I restart the server, it resets back to running the validations just once)
What can be the cause of that?
UPDATE :
The ActiveModel solution isn't possible for me because I'm using Rails 2.3.8. I still need to figure out where is the problem.
I would suggest you to use ActiveModel instead of writing your own Model engine from scratch, see this blog post for a tutorial you can also watch this screencast
I'm stabbing the dark here, but it sounds like the validations keep being included every time the model is loaded/saved.
Can you show us where you include it?
In Hyperactive Resource, instead of include we used:
# make validations work just like ActiveRecord by pulling them in directly
require "active_record/validations.rb"
extend ActiveRecord::Validations::ClassMethods
精彩评论