Fixed: view_path option not taken into account #361

Closed
wants to merge 2 commits into
from

Projects

None yet

4 participants

@sebastianludwig

The issue is similar to #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.

# 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 ;-)

sebastianludwig added some commits Nov 18, 2012
@sebastianludwig sebastianludwig Fixed: view_path option not taken into account
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
3257728
@sebastianludwig sebastianludwig Fixed: missing object root node
It's not a good idea to have a block variable with the same name as an variable outside the block scope (shadowing) - only applies to ruby 1.8
ee2dbc2
@databyte
Collaborator

Can you submit with tests? I can walk you through it if you have questions.

@sebastianludwig

Hi David, thanks for the offer. However after having spent the last two hours trying to get the gems together and in particular compile the native ones, only hitting dead ends, I fear I have to say: no. I'm very sorry and would have loved to provide a proper patch.

@databyte
Collaborator

Ok, I'll look at it some.

@vimutter
Contributor
vimutter commented Feb 8, 2013

Confirm issue. Can help somehow on this?

@nesquena nesquena closed this in e8fcf2e Feb 11, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment