Comments (12)
@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.
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.
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.
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.
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.
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.
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.
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.
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.
I tried out the fork from skyeagle and I'm still having the same issue.
from rabl.
I came up with a fix on a fork and requested a pull (#36). nesquena, thank you for your help on this.
from rabl.
@agibralter Thanks for the tip on render_views. That was throwing me off.
from rabl.
Related Issues (20)
- RABL, Devise and sessions/create.rabl
- Drop riot? Unmaintained, broken on Ruby 2.5. HOT 2
- How to use rabl with swagger? HOT 2
- Tagging a new version, or use master branch? HOT 1
- Unable to properly render json for an simple array of objects HOT 1
- How do I render free form metadata HOT 1
- Migrating to Rails 5 - Rabl returning Active Record object
- Rspec renders rabl as string instead of json
- Not able to get the rendered result in Rails console HOT 1
- Rabl output values as keys
- Rabl partial lookup based on requested api namespace
- upgrading from 0.14.0 to 0.14.1 is a breaking change HOT 8
- Child removes node from response when the provided object is an empty array HOT 2
- Rabl not renders collection properly HOT 4
- Is nested map valid in RABL?
- N+1 issues HOT 1
- some problems to install rable on windows HOT 2
- Avoid playing with `Oj` shared `default_options` HOT 2
- rabl tests failing with rr 3.x and Ruby 3 HOT 12
- Rails 7 compatibility HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rabl.