dewski / json_builder

Rails provides an excellent XML Builder by default to build RSS and ATOM feeds, but nothing to help you build complex and custom JSON data structures. JSON Builder is here to help.
http://garrettbjerkhoel.com/json_builder/
MIT License
244 stars 52 forks source link

Callbacks #14

Closed jaywhiting closed 12 years ago

jaywhiting commented 12 years ago

The callback script is not just wrapped around the outside "curly brackets" but inside them as well after ever "do" call. This is causing an "unexpected token" error.

dewski commented 12 years ago

Which version of json_builder are you using? Do you have an example json_builder view for me to reproduce this error?

Thanks!

jaywhiting commented 12 years ago
dogfights @recent_dogfights do |dogfight|

  id dogfight.id
  content dogfight.content
  options dogfight.options
  url dogfight_url(dogfight.id)
  created_at dogfight.created_at

  author dogfight.user do |user|
    id user.id
    name switch_name(user)
    url user_url(user)
    avatar_url user.avatar.url
  end

end

Which is giving me:

unexpected token at 'callback({"id": 79, "content": "Most recent dogfight!", "options": ["For", "Against"], "url": "http://localhost:3000/dogfights/79", "created_at": "2011-12-20T14:33:25Z", "author": callback({"id": 2, "name": "Johnny Cash", "url": "http://localhost:3000/randomizor222", "avatar_url": "http://barkles.com/assets/barkles_thumb.png"})})]}'

I am using the latest version (3.0.3)

dewski commented 12 years ago

This is a duplicate of issue #12. I just pushed up 3.0.4, can you confirm this fixed it?

jaywhiting commented 12 years ago

Confirmed, thanks!