Ruby on Rails
Tuesday, October 30, 2018
Hello all,
Or, what would be a kick-ass feature but probably difficult to implement, would be to stream from an active record relation, and send only the records that are included in the relation (even if they have just been created).
Anybody got any ideas how to do this? Filtering messages seems like such a basic thing but I can't find a way.
-- I've been searching a lot but wasn't able to find a solution for this (what I thought should be a really "simple" thing).
Basically, what I want to do is to create a subscription where the messages that are received by the subscriber are filtered based on the passed params.
For example, something like this:
class
PeopleChannel < ApplicationCable::Channel
# only send people that are older than params[:min_age]
def
subscribed
stream_for Person do |person|
person.age > params[:min_age] end
end
end
Or, what would be a kick-ass feature but probably difficult to implement, would be to stream from an active record relation, and send only the records that are included in the relation (even if they have just been created).
class
PeopleChannel < ApplicationCable::Channel
# only send things that are older than some age
def
subscribed
people = Person.where('age > ?', params[:min_age])
stream_for people
end
end
Anybody got any ideas how to do this? Filtering messages seems like such a basic thing but I can't find a way.
Stefan
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/60176de6-b536-4d21-a21e-4c00727542df%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment