Domanda

I have a class TaskBuilder to which I want to add various ActiveModel methods so it can take advantage of ActionPack. As I understand it, in Rails 4, this will do the trick:

class TaskBuilder
  include ActiveModel::Model

When I do this, I get this error:

task_builder.rb:2:in `<class:TaskBuilder>': 
  uninitialized constant TaskBuilder::Active_Model (NameError)

Note that originally I only intended to use validations, and simply included that module, with no issues, e.g.,

class TaskBuilder
  include ActiveModel::Validations

which worked fine. I am using Rails 4.0.0. What's going on here?

È stato utile?

Soluzione

Adding a require 'active_model' was mentioned in this old rails issue #5768 as being necessary due to the lazy loading of classes (autoload).

require 'active_model'

class TaskBuilder
  include ActiveModel::Model

Altri suggerimenti

I think you have a typo in your code. Please check that you have include ActiveModel::Model and not include Active_Model::Model (NOTE: _ should not be there) in your TaskBuilder class.

class TaskBuilder
  include ActiveModel::Model    ### Match this 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top