ccocchi / rabl-rails

Rails 4.2+ templating system with JSON, XML and Plist support.
MIT License
209 stars 51 forks source link

Only one node present and rendered, but executed twice. #66

Closed msenne closed 9 years ago

msenne commented 9 years ago

I might be misunderstanding something, but it does appear that for my single node it is running the block twice. This may also be an issue with RABL as opposed to rabl-rails, just let me know if I'm in the wrong place.

Here's my complete show.json.rabl:

object :@gizmo
attributes :id, :title, :description, :template

node :data do |gg|
  Rails.logger.info "ONCE........................\n\n"
  gizmo_data_params.empty? ? {} : gg.execute(gizmo_data_params)
end

Here's the (redacted) JSON output:

{"gizmo":{"id":5,"title":"Title","description":null,"template":"infohub","data":{"infohub":{"options":{"start_date":"2014-11-14","end_date":"2014-11-20","fids":[],"cids":[]}}}}}

There's only 1 'data' node in the output, but when debugging (binding.pry) the #execute method, triggered from the RABL node, I see that it executes twice. The log statement also appears twice in the console for each request.

Should this be happening as a standard practice? Is there something about my case in particular that would cause this? Thanks for any help!

ccocchi commented 9 years ago

I cannot reproduce your problem in a vanilla Rails app. When I use a node with a Rails.logger call inside, I only get one line in the log. Do you also have this problem when rendering the template outside of pry, like when running rails s?

msenne commented 9 years ago

Yes, I did have that issue without activating the debugger.

I can no longer reproduce this issue today, so I am closing the issue. Perhaps it was a case of needing to restart the application again after the changes.