Jump to content

The ultimate community for Ruby on Rails developers.


Filtering a model based on two other models.

rails ruby model relation controller views

  • Please log in to reply
No replies to this topic

#1 svajone



  • Members
  • 3 posts

Posted 07 August 2014 - 05:24 AM

So I have these models:

class User < ActiveRecord::Base
  has_many :ratings

class Rating < ActiveRecord::Base
  has_many :restaurant_ratings
  has_many :restaurant, through: :restaurant_ratings
  has_many :belongs

class Restaurant < ActiveRecord::Base
  has_many :restaurant_ratings
  has_many :ratings, through: :restaurant_ratings

class RestaurantRating < ActiveRecord::Base
  belongs_to :restaurant
  belongs_to :rating

Currently, when I want to view a restaurant on the controller's show method it works just fine. But right now, I am trying to figure out a way to filter a specific rating based on the current restaurant that is being viewed or shown as well as the current user who is logged in.


How would I best tackle this?

Also tagged with one or more of these keywords: rails, ruby, model, relation, controller, views

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users