プロジェクトのメインページのロールオーバーメニューを作成したいと思います。これは、サイトのすべてのページに表示されます。メインメニュー項目はとSHOWS
ですPROGRAMS
。誰かがこれらのボタンをロールオーバーすると、すべてのプログラムがポップアップdiv内に一覧表示されます。(プログラムは私のモデルの名前であり、ショー、映画、テレビ番組などの両方に使用する一般的な名前です。)
今...
これが私の協会です:
Program.rb
class Program
include Mongoid::Document
include Mongoid::Timestamps
field :title
field :content
belongs_to :program_category
end
program_category.rb
class ProgramCategory
include Mongoid::Document
include Mongoid::Timestamps
field :title
field :content
has_many :programs
end
program.title
メニュー内にsを表示する必要があります。このような:
SHOWS PROGRAMS
\- Lost \- Ellen
\- Dexter \- Marta Stuart
\- Alf \- Jey Leno Show
さて...私は今このようにこれをやっています:
home_controller.rb
クラスHomeController<ApplicationController
def index
@menu_programs = Program.all.where(program_category_id: "50a7c373ce3a6bcc0a000006").limit(10) #Yes, i think it's lame too...
@menu_shows = Program.all.where(program_category_id: "50a67f36ce3a6b840d000007").limit(10) # And yes I'm using MonoDB and Mongoid
end
ええ...それらはprogram_category_id
sであり、非常にハードコーディングされています!!
のような気がする...
これはベストプラクティスではありません!
質問は次のとおりです。
関連するモデルのメニュー項目を表示するためのベストプラクティスは何ですか?「EagerLoading」という名前の人がいると聞きましたが、誰かが説明してもらえますか?n + 1の問題のため、36のクエリがあります...
どんな提案も歓迎します。
ありがとうございました。