2013-02-06 15 views
6

In meiner Rails 3.2.11 und "Entwicklung" Umwelt gehören, wenn ich versuche, ein aktives Modell zu haben:Rails 3 ActiveModel: nicht ActiveModel :: Modell direkt

class DisponibilityApi 
    include ActiveModel::Model 

    attr_accessor :start_time, :end_time 
    validates :start_time, :end_time, :presence => true 

end 

Ich habe einen Fehler:

Nameerror: nicht initialisierte konstante ActiveModel :: Modell

Aber wenn ich es manuell schließen:

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 

Jetzt funktioniert es!

Fehle ich etwas?

Dank!

Antwort

-2

Es scheint, dass das ActiveModel :: Model-Modul nicht mehr existiert, Sie müssen manuell die Module einfügen, die Sie für Ihr Modell wünschen.

Auch wenn die Doc sagt, dass das Modul noch existiert, ein kurzer Blick in den ~/.rvm Ordnern beweist, dass es keine model.rb Datei mehr ist:

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 

, die lustig ist, weil diese Datei noch ist Gegenwart auf Github, aber nicht in der .gem.

16

ActiveModel :: Das Modell ist neu für Rails 4, weshalb es auf Github-Master angezeigt wird, aber nicht in den 3.x-Edelsteinen. Wenn Sie in der Version 3.x auf Github suchen, ist es auch nicht dort.

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

Für Rails 3.x müssen Sie manuell jedes der Module.

Um zu sehen, was es beinhaltet, sehen Sie sich die Datei im Master-Zweig an.

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

+0

Wenn Sie diese ActiveModel mit Simpleform verwenden wollen, müssen Sie auch die 'beharrte implementieren müssen?' Methode. – jethroo

Verwandte Themen