Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

template source is evaluated as empty #35

Closed
mrinterweb opened this issue Jun 2, 2011 · 12 comments
Closed

template source is evaluated as empty #35

mrinterweb opened this issue Jun 2, 2011 · 12 comments

Comments

@mrinterweb
Copy link
Contributor

I set a debug point on line 55 of lib/rabl/template.rb. When I template.inspect I get "app/views/attendee/show.rabl" which is correct, but template.source returns and empty string.

If I then do File.open(Rails.root + template.inspect, 'r') { |f| puts f.read } that produces:

extends("attendee/base")
object @attendee

app/views/attendee/base.rabl

attributes :oid, :first_name, :last_name

I am setting @Attendee in my show action and I can not figure out why the rendered result is:

{"attendee": {}}
@nesquena
Copy link
Owner

nesquena commented Jun 2, 2011

Can you experiment a bit, try a simple case and just do

# app/views/attendees/show.json.rabl
attributes :oid, :first_name, :last_name

and then make sure

# app/controllers/attendees_controller.rb
respond_to :json
def show
  @attendee = Attendee.first
  respond_with(@attendee)
end

and see if it is still blank?

@mrinterweb
Copy link
Contributor Author

I did that and I still end up with the same result. The only difference now is that template.inspect now shows "app/views/attendee/show.json.rabl" as I renamed it to json. The template.source still returns an empty string. I also replaced the contents of show.json.rabl as you recommended. The rendered result is still the same.

def show
  @attendee = Attendee.first
  respond_with {puts @attendee.inspect; @attendee}
end

The puts @attendee.inspect results in:

<Attendee _id: 4de6fb174820686dfc000001, _type: "Attendee", _id: BSON::ObjectId('4de6fb174820686dfc000001'), created_at: 2011-06-02 02:53:11 UTC, updated_at: 2011-06-02 02:53:11 UTC, email: "jimmy@aol.com", encrypted_password: "5d6bc901e1190e3f4c949b3683bbea0d913ced184c637884ff53e3085d0b708260a72f4e1c56537a380f21f03928cee42c20d49ca2f193f4dbeadff578a58c8b", authentication_token: nil, remember_created_at: nil, password_salt: "kw5kyj77gM8VXprBYAzk", reset_password_token: nil, failed_attempts: 0, unlock_token: nil, locked_at: nil, sign_in_count: 0, current_sign_in_at: nil, last_sign_in_at: nil, current_sign_in_ip: nil, last_sign_in_ip: nil, first_name: "Jimmy", last_name: "Dean", oid: "aEcDxHqEnc", event_oids: ["shQdQBIK21"]>

@nesquena
Copy link
Owner

nesquena commented Jun 2, 2011

Which ORM are you using? I think I am beginning to see the possible problem... Sorry should have asked that first, I have only tested RABL with Mongoid, Datamapper, ActiveRecord and MongoMapper. Does the attendee object respond to the valid? method?

@mrinterweb
Copy link
Contributor Author

I am using mongoid 2.0.1 with rails 3.0.7. The @Attendee instance is a Mongoid instance and it does respond to valid? with true.

@nesquena
Copy link
Owner

nesquena commented Jun 2, 2011

Fascinating, I have several apps (Rails 3 / Mongoid 2.0.1) using RABL right now, I have a hard time understanding why even the simplest case fails for you. Unfortunately don't have time to debug this right now :(

Try this out of interest:

app/views/attendees/show.json.rabl

node :foo do |a|
  "bar"
end

and see if that shows up with a foo : "bar" at least.

@mrinterweb
Copy link
Contributor Author

I modified show.json.rabl as recommended, and still nothing. Where I identify the problem is in RABL_ROOT/lib/rabl/template.rb line 56. The variable template when inspected appears to be the correct path to the show.json.rabl file, but when the source is an empty string template.source #=> "". Therefore, it does not matter what I put into show.json.rabl as the template instance believes the source is empty.

@mrinterweb
Copy link
Contributor Author

This is my backtrace

#0 ActionView::Template::Handlers::RablHandler.compile(template#ActionView::Template,...) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rabl-0.2.7/lib/rabl/template.rb:58
    #1 ActionView::Template::Handlers::Compilable::ClassMethods.call(template#ActionView::Template,...) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_view/template/handler.rb:15
    #2 ActionView::Template.compile(locals#Hash, view##<Class:0x00000104f1f..., mod#Module,...) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_view/template.rb:226
    #3 ActiveSupport::Notifications::Instrumenter.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications/instrumenter.rb:134
    #4 ActiveSupport::Notifications.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications.rb:52
    #5 ActionView::Template.render(view##<Class:0x00000104f1f..., locals#Hash) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_view/template.rb:127
    #6 ActiveSupport::Notifications::Instrumenter.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications/instrumenter.rb:59
    #7 ActiveSupport::Notifications.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications.rb:52
    #8 ActionView::Rendering._render_template(template#ActionView::Template) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_view/render/rendering.rb:56
    #9 ActionView::Rendering.render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_view/render/rendering.rb:26
    #10 ActionView::Base.render_with_haml 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/haml-3.1.1/lib/haml/helpers/action_view_mods.rb:13
    #11 AbstractController::Rendering._render_template(options#Hash) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:115
    #12 AbstractController::Rendering.render_to_body 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:109
    #13 ActionController::Renderers.render_to_body(options#Hash) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/renderers.rb:47
    #14 ActionController::Compatibility.render_to_body(options#Hash) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/compatibility.rb:55
    #15 AbstractController::Rendering.render_to_string 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:102
    #16 AbstractController::Rendering.render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:93
    #17 ActionController::Rendering.render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/rendering.rb:17
    #18 Benchmark.realtime 
       at line /Users/sean/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/benchmark.rb:40
    #19 Benchmark.ms 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/core_ext/benchmark.rb:5
    #20 ActionController::Instrumentation.cleanup_view_runtime 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/instrumentation.rb:40
    #21 ActiveRecord::Railties::ControllerRuntime.cleanup_view_runtime 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.7/lib/active_record/railties/controller_runtime.rb:15
    #22 ActionController::Instrumentation.render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/instrumentation.rb:39
    #23 ActionController::ImplicitRender.default_render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/implicit_render.rb:14
    #24 ActionController::Responder.default_render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/responder.rb:261
    #25 ActionController::Responder.default_render 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/responder.rb:190
    #26 ActionController::Responder.to_format 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/responder.rb:136
    #27 ActionController::Responder.respond 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/responder.rb:119
    #28 ActionController::Responder.call 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/responder.rb:112
    #29 ActionController::MimeResponds.respond_with 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/mime_responds.rb:0
    #30 AttendeeController.pair 
       at line /Users/sean/projects/hub/app/controllers/attendee_controller.rb:25
    #31 ActionController::ImplicitRender.send_action(method#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/implicit_render.rb:5
    #32 AbstractController::Base.process_action(method_name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:150
    #33 ActionController::Rendering.process_action 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/rendering.rb:11
    #34 AttendeeController._run__939219619784012487__process_action__77526239012026253__callbacks 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:18
    #35 AttendeeController._run_process_action_callbacks 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:410
    #36 ActiveSupport::Callbacks.run_callbacks(kind#Symbol) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/callbacks.rb:94
    #37 AbstractController::Callbacks.process_action(method_name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/callbacks.rb:17
    #38 ActiveSupport::Notifications::Instrumenter.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications/instrumenter.rb:30
    #39 ActiveSupport::Notifications.instrument(name#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.7/lib/active_support/notifications.rb:52
    #40 ActionController::Instrumentation.process_action(action#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/instrumentation.rb:29
    #41 ActionController::Rescue.process_action 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/rescue.rb:17
    #42 AbstractController::Base.process(action#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/base.rb:119
    #43 AbstractController::Rendering.process 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/abstract_controller/rendering.rb:41
    #44 ActionController::Testing.process_with_new_base_test(request#ActionController::Tes...,...) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/metal/testing.rb:12
    #45 ActionController::TestCase::Behavior.process(action#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:412
    #46 ActionController::TemplateAssertions.process 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:47
    #47 Devise::TestHelpers._catch_warden 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.3.4/lib/devise/test_helpers.rb:19
    #48 Devise::TestHelpers._catch_warden 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.3.4/lib/devise/test_helpers.rb:70
    #49 Devise::TestHelpers.process 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/devise-1.3.4/lib/devise/test_helpers.rb:19
    #50 ActionController::TestCase::Behavior.post(action#String) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.7/lib/action_controller/test_case.rb:355
    #51 RSpec::Core::Example.with_around_hooks 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:0
    #52 RSpec::Core::Example.with_pending_capture 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:46
    #53 RSpec::Core::Example.with_pending_capture 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:98
    #54 RSpec::Core::Example.run(example_group_instance#RSpec::Core::ExampleG..., reporter#RSpec::Core::Reporter,...) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example.rb:45
    #55 RSpec::Core::ExampleGroup.run_examples(reporter#RSpec::Core::Reporter) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:262
    #56 RSpec::Core::ExampleGroup.run(reporter#RSpec::Core::Reporter) 
       at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:232
    #57 at line /Users/sean/.rvm/gems/ruby-1.9.2-p180/gems/rspec-core-2.5.1/lib/rspec/core/example_group.rb:233

@nesquena
Copy link
Owner

nesquena commented Jun 2, 2011

I understand thanks for explaining, can you try this guy's fork: https://github.com/skyeagle/rabl

He fixed Rails 3 support and support for Rails 3.1. Perhaps this can also fix the template source issue you are experiencing.

@mrinterweb
Copy link
Contributor Author

I tried out the fork from skyeagle and I'm still having the same issue.

@mrinterweb
Copy link
Contributor Author

I came up with a fix on a fork and requested a pull (#36). nesquena, thank you for your help on this.

@agibralter
Copy link

@mrinterweb it seems like you were using rspec to test a controller without render_views! rspec-rails intentionally sets the source to "" so that you can test your controllers in isolation. If you want to test your views, you can use render_views to have your rabl templates rendered: https://www.relishapp.com/rspec/rspec-rails/v/2-5/docs/controller-specs/render-views

databyte added a commit that referenced this issue Jun 21, 2012
This resolves an issue whereby RSpec was intentionally
not loading the template source unless you called
render_views. The force load of templates from source
was introduced in Issue #35.
@mrinterweb
Copy link
Contributor Author

@agibralter Thanks for the tip on render_views. That was throwing me off.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants