In my Rails 3.2.11 and "development" environment when I try to have an active model:
class DisponibilityApi
include ActiveModel::Model
attr_accessor :start_time, :end_time
validates :start_time, :end_time, :presence => true
end
I have an error:
NameError: uninitialized constant ActiveModel::Model
But when I include it manually:
class DisponibilityApi
extend ActiveModel::Naming
extend ActiveModel::Translation
include ActiveModel::Validations
include ActiveModel::Conversion
attr_accessor :start_time, :end_time
validates :start_time, :end_time, :presence => true
end
Now it works !
Am I missing something ?
Thanks !
ActiveModel::Model is new for Rails 4, which is why it shows up on Github master, but not in the 3.x gems. If you look in the 3.x version branches on Github it is not there either.
https://github.com/rails/rails/tree/3-2-stable/activemodel/lib/active_model
For Rails 3.x you will need to include each of the modules manually.
To see what it includes, check out the file in the master branch.
https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With