0
def index
@project = Project.where(id: params[:id]).first
email = {:email => '[email protected]'}
respond_to do |format|
format.json { render :json => @project }
end
end
附加屬性當運行應用程序時,我會得到的結果是這樣的:Rails的包括JSON
{"project":{"id":1, "name" => "project name"}}
現在我想email
被包括在@project
JSON的附加屬性。
{"project":{"id":1, "name" => "project name", "email" => "[email protected]"}}
注意email
不是表場。
如何做到這一點?
對不起,我英文不好
看看這個http://stackoverflow.com/questions/6892044/add-virtual-attribute-to-json-output –