Answer the question
In order to leave comments, you need to log in
Rails to_json add your key and value?
Hello. Don't tell me, please. How can I add my key and value to the resulting
menu_requirement.to_json(
only: [ :number ], user: 555
}
{
"number": "KL-000000053",
"user': "555"
}
Answer the question
In order to leave comments, you need to log in
Correct as_json, not to_json.
h = menu_requirement.as_json(
only: [ :number ]
)
h[:user] = 555 # Если атрибут :user отсутствует в модели MenuRequirement
# puts h.inspect
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question