2013-02-06 17 views
6

Trong Rails tôi 3.2.11 và "phát triển" môi trường khi tôi cố gắng để có một mô hình hoạt động:Rails 3 ActiveModel: không thể bao gồm ActiveModel :: mẫu trực tiếp

class DisponibilityApi 
    include ActiveModel::Model 

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

end 

Tôi có một lỗi:

NameError: uninitialized ActiveModel liên tục :: mẫu

Nhưng khi tôi bao gồm nó bằng tay:

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 

Bây giờ nó hoạt động!

Tôi có thiếu gì đó không?

Cảm ơn!

Trả lời

-2

Dường như mô-đun ActiveModel :: Model không còn tồn tại nữa, bạn phải bao gồm các mô-đun theo cách thủ công mà bạn muốn cho mô hình của mình.

Ngay cả khi doc khẳng định rằng các mô-đun vẫn còn tồn tại, một cái nhìn nhanh chóng trong ~ thư mục/.rvm chứng minh rằng không có tập tin model.rb nữa:

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 

Đó là hài hước vì tệp này vẫn là hiện diện trên github nhưng không có trong .gem.

16

ActiveModel :: Mô hình mới cho Rails 4, đó là lý do tại sao nó xuất hiện trên Github master, nhưng không xuất hiện trong đá quý 3.x. Nếu bạn nhìn vào các nhánh phiên bản 3.x trên Github thì nó cũng không có ở đó.

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

Đối với Rails 3.x, bạn sẽ cần phải bao gồm mỗi mô-đun bằng tay.

Để xem nội dung bao gồm, hãy kiểm tra tệp trong nhánh chính.

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

+0

Nếu bạn muốn sử dụng ActiveModel này với SimpleForm, bạn cũng sẽ phải triển khai phương pháp 'persisted?'. – jethroo

Các vấn đề liên quan