nesquena/rabl — Issue #135: Empty Rabl rendering with valid object collection?
Author: kreeger
Created: 2011-10-31 18:54:16+00:00
State: open

I want to adopt Rabl in our project because it's supposed to handle JSON rendering a lot better than Rails (and from what I've read, it totally does). But I can't get it to return much of anything. I'm almost totally convinced I'm doing it wrong, however. I've got a `FeaturesController` with a `search` method that gets a list of `features` based on a `:query` parameter.

``` ruby
# controllers/features_controller.rb
def search
@features = Feature.search params[:query]
respond_to do |format|
format.json
end
end

# views/features/search.rabl
collection @features
```

When calling my search method, I can verify that `@features` isn't empty or nil; it's got stuff in it (I've dumped its contents to the console to be sure). The `.rabl` file is getting picked up, too; I'm seeing `Rendered features/search.rabl within layouts/application` in the server console output. I'm getting a `200 OK` response code, but the response is just empty. No brackets, nothing. It's like the `Rabl` file isn't being picked up all the way.

If, instead of `respond_to do`, I use the following, I get a result, but it's still not at all what I want.

``` ruby
def search
@features = Feature.search params[:query]
respond_with(@features, :layout => false)
end
```

``` json
[{"feature":{}},{"feature":{}},{"feature":{}}]
```

I'm at a loss. Am I doing it wrong? Need more info?