0

I am trying to use jBuilder to create a json file, and i can make the relationship "belongs_to" to work, but i don't what i can do for the "has_one".

So I have a Solution model:

class Solution 
  belongs_to :user
  has_one :world
end

I used this to create the json file, and I can get the name from solution.user.name, but how can i get the information about the world?

json.array! (@solutions) do |json, solution|
        json.id solution.id
        json.name solution.user.name
        json.world solution.world
end

Thanks in advance for your help!

Lisa
  • 2,809
  • 3
  • 24
  • 37

1 Answers1

0

So I had to change the relation in the model into:

belongs_to:world

Then it works.

Lisa
  • 2,809
  • 3
  • 24
  • 37