-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
None
Hello. I want create model for FAQ. I generated models:
class Content::HelpItem include Mongoid::Document embeds_many :records do def find_by_locale(locale) where(locale: locale) end def find_by_question(question) where(question: question).first end def find_by_answer(answer) where(answer: answer).first end end accepts_nested_attributes_for :records end
and
class Content::Record include Mongoid::Document field :locale, type: String field :question, type: String field :answer, type: String scope :english, where(locale: :en) scope :russian, where(locale: :ru) embedded_in :content_help_item end
If I do next:
rec_en = Content::HelpItem.records.find_by_locale 'en'
Then i have error:
NoMethodError: undefined method `records' for Content::HelpItem:Class from /home/johnbat26/.rvm/gems/ruby-1.9.3-p327@webex/gems/attr_encrypted-1.2.1/lib/attr_encrypted.rb:241:in `method_missing' from (irb):1 from /home/johnbat26/.rvm/gems/ruby-1.9.3-p327@webex/gems/railties-3.2.9/lib/rails/commands/console.rb:47:in `start' from /home/johnbat26/.rvm/gems/ruby-1.9.3-p327@webex/gems/railties-3.2.9/lib/rails/commands/console.rb:8:in `start' from /home/johnbat26/.rvm/gems/ruby-1.9.3-p327@webex/gems/railties-3.2.9/lib/rails/commands.rb:41:in `<top (required)>' from script/rails:6:in `require' from script/rails:6:in `<main>
Why?