Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3 ActiveModel: cannot include ActiveModel::Model directly

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 !

like image 833
mishaker Avatar asked Feb 06 '13 19:02

mishaker


1 Answers

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

like image 144
t_itchy Avatar answered Sep 28 '22 03:09

t_itchy