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 –