Quantcast
Viewing latest article 2
Browse Latest Browse All 2

Rails feed from multiple models

Based on this question, I have created a controller:

@activities = (@plays + @wants).sort_by {|a| a.created_at}.reverse

and a view:

- @plays.each do |play|
  You played #{play.game.name}

However it can not be displayed: undefined method 'play' for #Want:0x007f39ab8e99e0

How can I access different fields of each dependent model, and their names? Like:

- @activities.each do |activity|
  - if activity.model_name = Play
   You played #{activity.model.name}
  - else      
   You want #{play.want.name}

Viewing latest article 2
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>