Reputation: 3
I have this in a controller:
def get_tags
person = Person.where({fuid: params[:fuid]})
render json: person, :only=>[:fuid], :include => [
:hashtags => {
:except => [:created_at, :updated_at],
:methods => :person_count
}
]
end
I am including hashtags but I need to filter those hashtags for only the ones that have active = 1
. Is there a way to do this?
Upvotes: 0
Views: 41
Reputation: 196
You could do this in the model:
class Person < ActiveRecord::Base
has_many :active_hashtags,-> { where active: 1 }, class_name: 'Hashtags'
end
Then in your controller:
render json: person :only=>[:fuid], :include => [
:active_hashtags => {
:except => [:created_at, :updated_at],
:methods => :person_count
}
]
Upvotes: 1