0
我输出一个JSON数组的ActiveRecord对象,在运行Ruby 1.9.3-p545和Rails 4.0.3的本地机器上,它使用.json扩展名完美输出JSON,还如果选择.xml扩展名,则输出xml。显示对象ID而不是JSON输出
当我将这段代码部署到运行Ruby 1.9.3和Rails 4.0.3的弹性beanstalk环境中时,会出现这个问题。
当我在Passenger(standalone)或Puma上将此代码部署到运行Ruby 2.0.0的Rails 4.0.3的弹性beanstalk环境中时,也会出现此问题。
输出是仅此使用以.json时:
"#<ActiveRecord::Relation::ActiveRecord_Relation_CrmOrganisation:0x000000083ad5b0>"
真正奇怪的是,这同时在生产环境中使用的.xml时完美的作品,同时也完美的作品在当地。
我知道这与包含的关系没有任何关系,因为当include:被移除时它会产生相同的结果。
这里是我的代码:
class ApiCrmOrganisationsController < ApplicationController
include ApiHelper, ApplicationHelper
before_filter :authenticate_company
respond_to :xml, :json
def index
@crm_organisations = CrmOrganisation.where('updated_at > ? ', params[:delta]).order('organisation_name ASC').paginate(:page => params[:page]).per_page(params[:quantity].to_i)
respond_with @crm_organisations, :include => determine_include
end
end
你在你的观点定义你的JSON文件? – user3383458
有没有必要这样做,如果这是问题,它不会在本地工作。我实际上已经解决了这个问题,只是想回答这个问题:)而且这真是一个蠢事......我的4个小时我想回到红宝石! – Aaron