Question: I have the following Scope in my Rails app, which is used to fetch active `Choices` from the database based on the `current_user`. This works just fine, but if there is no `current_user` the the code fetches alle the `Choices` in the database. Here I just want it to fetch nothing.

```
scope :active,  lambda{|user| user ? { :conditions => ["deliverydate = ? and user_id = ?", Date.tomorrow, user.id], :order => 'id DESC'} : {} }

```

How do I rewrite thee above to return nothing if there is no `current_user`?

The problem is that I'm using [Pusher](http://pusher.com/) to push new data to the website, but if the user session expires then all data are pushed instead of nothing.. hopes this makes sense :)

Answer: 
As scopes return an `ActiveRecord::Relation` instance so it would be more correct to return empty `ActiveRecord::Relation` object like it's described [here](https://stackoverflow.com/questions/4877931/how-to-return-an-empty-activerecord-relation).

So, you have to add `:none` scope which does the trick:

```
scope :none, limit(0)

```

and then use it inside your scope like:

```
scope :active, ->(user = nil) { user ? { :conditions => ["deliverydate = ? and user_id = ?", Date.tomorrow, user.id], :order => 'id DESC'} : none }

```
```
scope :active,  lambda{|user| user ? { :conditions => ["deliverydate = ? and user_id = ?", Date.tomorrow, user.id], :order => 'id DESC'} : nil }

```