Coder Social home page Coder Social logo

Comments (12)

agibralter avatar agibralter commented on July 19, 2024 1

@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

from rabl.

nesquena avatar nesquena commented on July 19, 2024

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?

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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: "[email protected]", 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"]>

from rabl.

nesquena avatar nesquena commented on July 19, 2024

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?

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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.

from rabl.

nesquena avatar nesquena commented on July 19, 2024

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.

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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.

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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

from rabl.

nesquena avatar nesquena commented on July 19, 2024

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.

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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

from rabl.

mrinterweb avatar mrinterweb commented on July 19, 2024

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

from rabl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.