Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fixed: view_path option not taken into account #361

Closed
wants to merge 2 commits into from

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
@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

Confirm issue. Can help somehow on this?

@nesquena nesquena closed this in e8fcf2e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 18, 2012
  1. @sebastianludwig

    Fixed: view_path option not taken into account

    sebastianludwig authored
    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
  2. @sebastianludwig

    Fixed: missing object root node

    sebastianludwig authored
    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
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 3 deletions.
  1. +2 −2 lib/rabl/builder.rb
  2. +5 −1 lib/rabl/partials.rb
View
4 lib/rabl/builder.rb
@@ -34,8 +34,8 @@ def compile_hash(options={})
extends(settings[:file], settings[:options], &settings[:block])
end if @options.has_key?(:extends)
# Attributes
- @options[:attributes].each_pair do |attribute, options|
- attribute(attribute, options)
+ @options[:attributes].each_pair do |attribute, attr_options|
+ attribute(attribute, attr_options)
end if @options.has_key?(:attributes)
# Node
@options[:node].each do |settings|
View
6 lib/rabl/partials.rb
@@ -76,7 +76,11 @@ def fetch_rails_source(file, options={})
source_format = rendered_format unless rendered_format == :html
context_scope.lookup_context.find(file, [], partial, [], {:formats => [source_format]})
end }
- template = lookup_proc.call(false) rescue lookup_proc.call(true)
+ begin
+ template = lookup_proc.call(false)
+ rescue
+ lookup_proc.call(true) rescue return nil
+ end
template.identifier if template
elsif source_format && context_scope.respond_to?(:view_paths) # Rails 2
template = context_scope.view_paths.find_template(file, source_format, false)
Something went wrong with that request. Please try again.