在我的控制,我有:如何使用Rails中的include選項渲染array.to_json?
def index
# Array of Task objects
@tasks = Task.get_tasks(current_user, params)
respond_to do |format|
format.html
# Sends correct JSON but not including the 'author' object in it
# format.json { render :json => @tasks.to_json(:include => [:author]) }
# With this the JSON look correct but is interpreted as a string in the JavaScript code
format.json { render :json => @tasks.map { |e| e = e.to_json(:include => [:author]) } }
end
end
你知道有「乾淨」的解決方案,正確傳遞:include
選項時,渲染陣列轉換成JSON?
編輯
我使用MongoDB的
EDIT(2)
我從mongoid (2.0.1)
更新爲mongoid (2.0.2)
和它的作品。 對不起。
確定嗎?我已經做了一些快速測試,數組似乎很好... – lucapette