How to convert records including 'include' associations to JSON

后端 未结 2 1712
终归单人心
终归单人心 2020-12-31 15:26

If I do something like:

result =  Appointment.find( :all, :include => :staff )
logger.debug { result.inspect }

then it only prints out t

2条回答
  •  温柔的废话
    2020-12-31 15:40

    Check out ActiveRecord::Serialization and ActionController::Base (see section: "Rendering JSON")

    def show
      @appointment = Appointment.find(:all, :include => :staff)
      respond_to do |format|
        format.html
        format.js { render :json => @appointment.to_json(:methods => [:staff]) }
      end
    end
    

提交回复
热议问题