0
在我的Rails應用程序中,我試圖爲一個模型構建API,但我無法執行少量方法。有沒有知道哪裏錯了。請提出建議。Rails 4 + Mongoid + API調用 - 無法定義幾個條件
模式 - 用戶
class User
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :display_name, type: String
field :user_type, type: String
field :city_id, type: String
field :country_id, type: String
field :tags, type: String
field :status, type: Mongoid::Boolean
field :rating, type: Array
end
API 1 全部使用一覽 - User.All
但我不能夠採取選擇列名。在模型中試圖定義範圍,但仍然給出錯誤。即。
User.selected_column
scope :selected_column, -> { select("id, name") }
API 2. 頂級用戶的列表 - User.rating_five
模型試圖界定範圍,但仍然給出錯誤。即。
User.rating_five
scope :rating_five, -> { .where(:rating["average"] > 4.6) }
讓我檢查一下,讓你知道,如果我發現任何問題。謝謝 – Rubyist