amatsuda/jb

undefined local variable or method `json'

matissg opened this issue · 3 comments

I'm trying to implement this in my index.json.jb

json[:data] = @positions.map do |p|
  {
    id: p.id,
    name: p.name,
    ptype: p.ptype,
    address: p.address,
    code: p.code,
    light: p.light,
    countries: {
      id: p.country.id,
      name: p.country.name
    },
    cities: {
      id: p.city.id,
      name: p.city.name
    }
  }
end
json

however I get this error:

undefined local variable or method `json'
Did you mean?  JSON

What am I doing wrong here, please?

I need to have something like this as result:

{
    "data": [{
        "id": 2,
        "name": "my_name",
        "ptype": "my_type",
        "address": "some street",
        "code": "some code",
        "light": "false",
        "countries": {
            "id": 1,
            "name": "Germany"
        },
        "cities": {
            "id": 1,
            "name": "Berlin"
        }
    }]
}

I'm using Rails 5.1.4 and Ruby 2.4.2.

prepend it with json = {}

@andriytyurnikov That simple :) Thank you!

This is a ruby-error, not related to jb. /voteclose 🙂