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

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -