How to nest queries in ruby?

I don’t know how to nest subqueries into a big one. I know the query in
sql but i don’t know how to translate it to LinQ/ActiveRecord/ruby.

The point is to know how many users have done this 4 activities in the
same festival, the sql query is the following:

SELECT count(distinct user) FROM stats where festivalId=‘fest000’
and user in (select user from stats where activity=‘checkins’)
and user in (select user from stats where activity=‘programs’)
and user in (select user from stats where activity=‘status’)
and user in (select user from stats where activity=‘pictureUpload’);

i’ve tried different things but i dont find the correct syntax to manage
it.

thanks in advance!!