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

Unknown keyword problem #9

Open
zeitnot opened this issue Dec 19, 2016 · 3 comments
Open

Unknown keyword problem #9

zeitnot opened this issue Dec 19, 2016 · 3 comments

Comments

@zeitnot
Copy link

zeitnot commented Dec 19, 2016

I am using rails 4.2.7.1. Basically when I set { id: ''} value to .jb template file it says unknown keyword: id. Then I add .to_json at and end of { id: ''} hash expression. But at this stage it produces bad JSON-like string which browsers do not understand.

"{\"id\":\"\"}\n}\n\n"

Due to the fact that there are special characters in this string browsers do not understand whether the string is JSON or not even if the server sends Content-Type: application/json header. Maybe there is a proper way but as I read from the documentation I could not find any way.

@binarydev
Copy link

JB essentially calls to_json on whatever your template returns as a final value/object, so when you call to_json yourself, you're basically forcing JB to call to_json on an already JSON-ified string, which is why you're getting that 2nd error. I don't know if you have anything (aside from the basic hash you've shown us in your template), but I don't see why id as a key in a hash would cause JB or Ruby to interpret it as a variable rather than a key name. Have you tried using id as a string instead?

'''
{ "id": "" }
'''

@zeitnot
Copy link
Author

zeitnot commented Dec 28, 2016

@binarydev I have tried the syntax like following:

{ "id": "" }

It says unknown keyword: id. But when I try

{ "id" => "" }

it says no implicit conversion of Hash into String

@marckohlbrugge
Copy link

marckohlbrugge commented Apr 27, 2018

Update: Problem solved! I had to add render layout: false to my Rails controller action.


Original question:

Did you ever figure this out? I'm running into the exact same problem.

Here's the surrounding code Rails 5.1 shows along with the error message:

      [302, { "Location" => @target }, []]
    else
      @app.call(env) # <-- here's where it goes wrong
    end
  end

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

3 participants