我已經下載了模板Rails 3 + Mongoid + Devise並安裝。Mongoid + devise error Mongoid :: Errors :: InvalidCollection
我已經創建了一個腳手架汽車與關係用戶設計模型。我有我的用戶模型驗證碼:
class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
field :name
validates_presence_of :name
validates_uniqueness_of :name, :email, :case_sensitive => false
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
embeds_many :cars
end
和我的汽車模型我有下面的代碼:
class Car
include Mongoid::Document
field :title
field :description
field :image_url
field :price
field :published_on, :type => Date
validates_presence_of :title, :description, :image_url, :price
validates :title, :length => { :maximum => 70 }
validates :description, :length => { :maximum => 2000 }
validates :price, numericality: {greater_than_or_equal_to: 0.01}
validates :image_url, allow_blank: true, format: {
with:
%r{\.(gif|jpg|png)$}i,
message: 'must be a URL for GIF, JPG or PNG image.'
}
embedded_in :user, inverse_of: :cars
end
當我刷新頁面,我得到了一個錯誤:
Mongoid :: Errors :: InvalidCollection in Cars#index
不允許訪問Car的集合,因爲它是一個emb edded文檔,請從根文檔訪問集合。
這個代碼有什麼問題? Thankyou
我有使用引用,現在罰款:D。非常感謝你! – hyperrjas