def class Question < ActiveRecord::Base
has_many :answers
has_one :user_answer, -> (uid) { where(user_id: uid) }
end
@question = Question.find(5)
@question.to_json(:include => user_answer(2) )
In the above example I have an association that expects a parameter. How can I include this association in a json include with the parameter?
I have solved the issue using an instance variable, but it's annoying. I'd like to find a better solution. This is not the same example, but a simpler one.