Rails 3 ActiveModel: cannot include ActiveModel :: Model directly

In my Rails 3.2.11 and development environment, when I try to create 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 turn it on 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!

+6
source share
2 answers

ActiveModel :: The model is new to Rails 4, so it appears on the main Github server, but not in the 3.x gems. If you look in the branches of version 3.x on Github, this is also not the case.

https://github.com/rails/rails/tree/3-2-stable/activemodel/lib/active_model

For Rails 3.x, you will need to enable each of the modules manually.

To find out what it includes, check the file in the main branch.

https://github.com/rails/rails/blob/master/activemodel/lib/active_model/model.rb

+16
source

It seems that the ActiveModel :: Model module no longer exists, you must manually enable the modules you want for your model.

Even if the document states that the module still exists, a quick look in the ~ / .rvm folder proves that the model.rb file is no longer there:

 activemodel-3.2.11/lib ยป pwd /Users/Intrepidd/.rvm/gems/ruby-1.9.3-p327-turbo/gems/activemodel-3.2.11/lib activemodel-3.2.11/lib ยป ls active_model active_model.rb activemodel-3.2.11/lib ยป ls -l active_model total 280 -rw-r--r-- 1 Intrepidd staff 16574 9 Jan 00:39 attribute_methods.rb -rw-r--r-- 1 Intrepidd staff 4556 9 Jan 00:39 callbacks.rb -rw-r--r-- 1 Intrepidd staff 2338 9 Jan 00:39 conversion.rb -rw-r--r-- 1 Intrepidd staff 4879 9 Jan 00:39 dirty.rb -rw-r--r-- 1 Intrepidd staff 12087 9 Jan 00:39 errors.rb -rw-r--r-- 1 Intrepidd staff 5259 9 Jan 00:39 lint.rb drwxr-xr-x 3 Intrepidd staff 102 9 Jan 00:39 locale drwxr-xr-x 4 Intrepidd staff 136 9 Jan 00:39 mass_assignment_security -rw-r--r-- 1 Intrepidd staff 8720 9 Jan 00:39 mass_assignment_security.rb -rw-r--r-- 1 Intrepidd staff 6478 9 Jan 00:39 naming.rb -rw-r--r-- 1 Intrepidd staff 4257 9 Jan 00:39 observer_array.rb -rw-r--r-- 1 Intrepidd staff 8163 9 Jan 00:39 observing.rb -rw-r--r-- 1 Intrepidd staff 38 9 Jan 00:39 railtie.rb -rw-r--r-- 1 Intrepidd staff 2939 9 Jan 00:39 secure_password.rb -rw-r--r-- 1 Intrepidd staff 4304 9 Jan 00:39 serialization.rb drwxr-xr-x 4 Intrepidd staff 136 9 Jan 00:39 serializers -rw-r--r-- 1 Intrepidd staff 319 9 Jan 00:39 test_case.rb -rw-r--r-- 1 Intrepidd staff 2339 9 Jan 00:39 translation.rb drwxr-xr-x 13 Intrepidd staff 442 9 Jan 00:39 validations -rw-r--r-- 1 Intrepidd staff 7961 9 Jan 00:39 validations.rb -rw-r--r-- 1 Intrepidd staff 6227 9 Jan 00:39 validator.rb -rw-r--r-- 1 Intrepidd staff 172 9 Jan 00:39 version.rb 

This is ridiculous because this file is still present in github, but not in .gem.

-2
source

All Articles