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

Popular posts from this blog

javascript - How to process users in one specific order using map o each function? -

java - Two interface have same method name with different return type -

javascript - Linking from page A to a specific iframe on page B -