samedi 30 janvier 2016

Rails - pull attribute value from table using two conditions

I have two tables in my rails application: a user table and an activity table. The user has many activities. Right now, I am trying to find out how to print out the activity_name where the activity_type = :personal AND where user_id = current_user.id.

In my activities index file i have the following:

<% @activities.where(:user_id => current_user.id).where(:activity_type => :personal).each do |activity| %>
<%= activity.activity_name %>
<% end %>

Nothing prints out on the page - I definitely have added users and activities to the database, as I have checked the rails consoler. Have I set up the each do loop incorrectly? Is there a different way to query this data?

Aucun commentaire:

Enregistrer un commentaire