ruby on rails - How to query two tables from database in one controller -
i have 2 tables 1 many (1 challenge many entry) want last entry challenges want title of challenge last entry.
so far have:
def index @discovers = challenge.all.map{|c| c.entries.last} end
how add fact want challenge.title?
def index @challenges = challenge.all end
then inside view
<% @challenges.each |challenge| %> <%= challenge.title %> # give challenge title <%= challenge.entries.last %> # give last entry challnge <% end %>
Comments
Post a Comment