ruby on rails - how to display data from a associated model -
ruby on rails - how to display data from a associated model -
currently stuck on problem
i have company.rb model has_many :applications
the application.rb model belongs_to :company , has_many :answers
the answer.rb model belongs_to :application.rb , has_many :users
the user.rb model has_many :answers
i allow company create application. there can input questions. user can view them , answers stored in answer.rb.
what i'm trying display current_company.applications have received answer.
i tried this:
<% @applications.all.each |f| %> <%= f.answers.answer_1 %><br> <% end %>
whilst having controller:
def applicants @applications = current_company.applications end
however undefined method `answer_1'. doesn't seem i'm available access it. store this: applications has company_id , answers has application_id , user_id.
i thought doing way i'm able access applications created current company. there can view application_id in answers one's i'm outputting it's not working.
i think understood way can access nested models wrongly.
when application has_many: :answers, @application.answers
collection can iterate through. illustration (in view):
<% @applications.each |application| %> <% application.answers.each |answer| %> <%= answer.text %> <% end %> <% end %>
(assuming reply model has text attribute).
ruby-on-rails ruby-on-rails-3
Comments
Post a Comment