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
243 stars 52 forks source link

Block nullifies instance variables #7

Closed lagartoflojo closed 12 years ago

lagartoflojo commented 12 years ago

With code looking like this:

# show.json.json_builder
href @person.href
url do
  href @person.href
end

Rails throws:

undefined method `href' for nil:NilClass

Extracted source (around line #3):

1: href @person.href
2: url do
3:   href @person.href
4: end

Line 1 works as expected, but @person is nil in line 3.

dewski commented 12 years ago

This has also been fixed and pushed along with 3.0.2. The issue was the instance variable scope wasn't getting passed down to the other JSON blocks. Thanks for reporting this!

lagartoflojo commented 12 years ago

Thanks! =) I'll keep reporting anything else I find.