2013-02-06 10 views
6

W moim Rails 3.2.11 i "rozwój" środowisko gdy próbuję mieć aktywny model:Rails 3 ActiveModel: nie może zawierać ActiveModel :: model bezpośrednio

class DisponibilityApi 
    include ActiveModel::Model 

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

end 

mam błąd:

NameError: niezainicjowanymi stałą ActiveModel :: model

Ale kiedy to ręcznie:

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 

Teraz działa!

Czy brakuje mi czegoś?

Dzięki!

Odpowiedz

-2

Wygląda na to, że moduł ActiveModel :: Model już nie istnieje, musisz ręcznie dołączyć moduły, które chcesz dla swojego modelu.

Nawet jeśli dokument stwierdza, że ​​moduł wciąż istnieje, szybkie spojrzenie w folderze ~/.rvm dowodzi, że nie ma już plik model.rb:

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 

To zabawne, ponieważ ten plik jest nadal obecny na github, ale nie w .gem.

16

ActiveModel :: Model jest nowy dla Rails 4, dlatego pojawia się na Github Master, ale nie w klejnotach 3.x. Jeśli spojrzysz na gałęzie wersji 3.x na Githubie, to też tam nie jest.

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

dla szyn 3.x trzeba będzie obejmować każdy z modułów ręcznie.

Aby zobaczyć, co obejmuje, sprawdź plik w gałęzi głównej.

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

+0

Jeśli chcesz korzystać z tej ActiveModel z SimpleForm trzeba będzie również wdrożenie trwało? '' Metody. – jethroo

Powiązane problemy