ruby on rails - Filter elements from related table -


here tables

i'm displaying on homepage current bets (current option of status attribute) members. here code:

<% @bets.where(status: "current").each |bet| %> <%= bet.match_name %> <%= bet.bet_choice %> <% end %> 

(where @bets = bet.all in page controller)

what display on homepage current bets members in "team" (team boolean in user).

how can that?

assuming that, have proper associations defined in user , bet models.

try this:

user.where(team: true).joins(:bets).where('bets.status' => 'current') 

update_1:

i see have column id_user in bets table, should user_id instead, assuming associations like: user has_many bets , bet belongs_to user.

update_2:

if want such bets , loop through bets collection, have modify above query little bit this:

bet.where(status: "current").joins(:user).where('users.team' => 'true') 

Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -