Tôi có một mô hình như thế này:Rails + MongoID - Truy vấn bởi thuộc tính
class Lesson
include Mongoid::Document
field :title, :type => String
field :category, :type => String
field :price, :type => Float
field :description, :type => String
field :user_id, :type => String
validates_presence_of :title
validates_presence_of :category
validates_presence_of :price
validates_presence_of :user_id
attr_accessible :title, :category, :description, :price
end
Và tôi đang cố gắng để truy vấn như thế này:
@lessons_by_user = Lesson.find_by_user_id current_user.id
Và Tôi nhận:
phương thức chưa xác định `find_by_user_id 'cho Bài học: Lớp
Tôi làm cách nào để truy vấn bằng thuộc tính cụ thể trong MongoID?
tôi biết làm thế nào để làm điều đó như thế này:
@lessons = Lesson.all(:conditions=>{:user_id=>current_user.id.to_s})
nhưng tôi tự hỏi nếu có một phím tắt ...
Tuyệt vời. Thực sự tốt để biết. –