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!
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