この場合のレールヘルパーはありますか?
Survey、どのhas_many質問、どのhas_many回答があります。
s = Survey.first
s.answers # => Returns the answers of all the survey questions
ここでホイールを再作成したくありませんでした。
この場合のレールヘルパーはありますか?
Survey、どのhas_many質問、どのhas_many回答があります。
s = Survey.first
s.answers # => Returns the answers of all the survey questions
ここでホイールを再作成したくありませんでした。
それは組み込まれています:
class Survey < ActiveRecord::Base
has_many :questions
has_many :answers, :through => :questions
# ...
end
それでおしまい。これで電話をかけることができsurvey.answers、すべての回答が得られます。
:throughオプション(およびその制限)については、こちらをご覧ください