nesquena/rabl — pull request #361 by sebastianludwig (2012-11-18 13:52:20+00:00)
Title: Fixed: view_path option not taken into account

The issue is similar to https://github.com/nesquena/rabl/issues/272

Passing a view_path option to partial or extend is only taken into account if fetch_rails_source returns nil / false, but instead it raised an exception if it couldn't find anything.

```ruby
# routes.rb
namespace :api, :defaults => { :format => :json } do
namespace :v1 do
resources :sprints, :only => [:index] do
get 'show', :on => :member, :constraints => { :id => /\d+/ }
end
end
end

# app/views/api/v1/sprints/show.json.rabl
object @sprint

attribute :id, :number

child :graphs do
extends "graphs/show", :view_path => 'app/views/api/v1' # view_path doesn't have an effect without patch
end
```

Without the patch I get the following error
```
ActionView::MissingTemplate in Api/v1/sprints#show

Showing /Users/sebastian/projects/Burndown/rails/app/views/api/v1/sprints/show.json.rabl where line #1 raised:

Missing partial graphs/show with {:locale=>[:en], :handlers=>[:coffee, :erb, :rabl, :builder], :formats=>[:json]}. Searched in:
* "[,.]rails/app/views"

Extracted source (around line #1):

1: object @sprint
2:
3: attribute :id, :number
4:

actionpack (3.2.8) lib/action_view/path_set.rb:58:in `find'
actionpack (3.2.8) lib/action_view/lookup_context.rb:109:in `find'
rabl (0.7.6) lib/rabl/partials.rb:77:in `fetch_rails_source'
rabl (0.7.6) lib/rabl/partials.rb:79:in `call'
rabl (0.7.6) lib/rabl/partials.rb:79:in `fetch_rails_source'
rabl (0.7.6) lib/rabl/partials.rb:39:in `fetch_source'
rabl (0.7.6) lib/rabl.rb:53:in `source_cache'
rabl (0.7.6) lib/rabl/partials.rb:34:in `fetch_source'
rabl (0.7.6) lib/rabl/partials.rb:12:in `partial'
rabl (0.7.6) lib/rabl/builder.rb:112:in `extends'
rabl (0.7.6) lib/rabl/builder.rb:34:in `compile_hash'
rabl (0.7.6) lib/rabl/builder.rb:33:in `each'
rabl (0.7.6) lib/rabl/builder.rb:33:in `compile_hash'
rabl (0.7.6) lib/rabl/builder.rb:21:in `build'
rabl (0.7.6) lib/rabl/builder.rb:142:in `cache_results'
rabl (0.7.6) lib/rabl/builder.rb:20:in `build'
rabl (0.7.6) lib/rabl/engine.rb:51:in `to_hash'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `map'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `send'
activerecord (3.2.8) lib/active_record/associations/collection_proxy.rb:89:in `method_missing'
rabl (0.7.6) lib/rabl/engine.rb:51:in `to_hash'
rabl (0.7.6) lib/rabl/engine.rb:37:in `send'
rabl (0.7.6) lib/rabl/engine.rb:37:in `render'
rabl (0.7.6) lib/rabl/engine.rb:275:in `cache_results'
rabl (0.7.6) lib/rabl/engine.rb:37:in `render'
rabl (0.7.6) lib/rabl/partials.rb:27:in `object_to_hash'
rabl (0.7.6) lib/rabl/builder.rb:96:in `child'
rabl (0.7.6) lib/rabl/builder.rb:46:in `compile_hash'
rabl (0.7.6) lib/rabl/builder.rb:45:in `each'
rabl (0.7.6) lib/rabl/builder.rb:45:in `compile_hash'
rabl (0.7.6) lib/rabl/builder.rb:21:in `build'
rabl (0.7.6) lib/rabl/builder.rb:142:in `cache_results'
rabl (0.7.6) lib/rabl/builder.rb:20:in `build'
rabl (0.7.6) lib/rabl/engine.rb:49:in `to_hash'
rabl (0.7.6) lib/rabl/engine.rb:61:in `to_json'
rabl (0.7.6) lib/rabl/engine.rb:37:in `send'
rabl (0.7.6) lib/rabl/engine.rb:37:in `render'
rabl (0.7.6) lib/rabl/engine.rb:275:in `cache_results'
rabl (0.7.6) lib/rabl/engine.rb:37:in `render'
app/views/api/v1/sprints/show.json.rabl:1:in `_app_views_api_v__sprints_show_json_rabl___11409293_2181107300'
actionpack (3.2.8) lib/action_view/template.rb:145:in `send'
actionpack (3.2.8) lib/action_view/template.rb:145:in `render'
...
```

It's still not perfect, because you have to specify the `view_path` (it'd be best to be picked up automatically), but it's better than not working at all ;-)