Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jbuilder parsing ignores conditionals when finding partials #230

Open
corporealfunk opened this issue Jul 13, 2017 · 0 comments
Open

jbuilder parsing ignores conditionals when finding partials #230

corporealfunk opened this issue Jul 13, 2017 · 0 comments

Comments

@corporealfunk
Copy link

When we have a jbuilder template like this:

json.name = @my_object.name

if @my_object.child
  json.child do
    json.partial! 'children/show', :child => @my_object.child
  end
else
  json.child = nil
end

This is how we might nest or include parent/child relationships in jbuilder, by utilizing a jbuilder partial for the child.

It is clear here that if @my_object.child is falsey, we don't want the partial to be parsed. Normal jbuilder template parsing would not attempt to parse the 'children/show' partial.

However, the gon jbuilder module does a simple text scan of each line of the the jbuilder template looking for lines that contain the word =~ 'partial', and then it actually attempts to create output from that partial, regardless of where that partial may sit in a conditional. In cases where the partial should not be parsed, there are probably good reasons for this, and attempting to parse it might cause errors (especially "xyz" for nil:NilClass errors), since the partial is trying to access methods on the @my_object.child variable, which is nil, or at least not an object or hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant