Giter Site home page Giter Site logo

Comments (2)

apotonick avatar apotonick commented on July 30, 2024

Hi @lister, I am planning the following behaviour:

directory.extend(DirectoryRepresenter).to_json(date: 10.days.ago)

The options passed to to_json are now propagated to the reader method if it accepts arguments.

module DirectoryRepresenter
  # ..

  def files(options={})
    super.modified_after(options[:date])
  end

So, it is still up to you to write the filter logic, however, the representer simply passes all options to the accessors. What do you think?

from representable.

markedmondson avatar markedmondson commented on July 30, 2024

I need this functionality too, and the passing through of render local parameters to extended representers, consider something similar to the following (using HAL with roar-rails):

class Doctor
    has_many :appointments
    has_many :patients, :through => appointments
end

class Patient
    has_many :appointments
    has_many :doctors, :through => appointments
end

class Appointment
    belongs_to :doctor
    belongs_to :patient
end

Trying to retrieve a list of a doctors patients and appointments through: /doctors/1/patients.json

class PatientsController
    represents :json, Patient

    def index
        patients = Doctor.find(params[:id]).patients
        respond_with patients.to_a, :doctor_id => params[:id]
    end
end

module PatientsRepresenter
    collection :patients, :extend => PatientRepresenter

    def patients
        each
    end
end

module PatientRepresenter
    collection :appointments, :class => Appointment, :extend => AppointmentRepresenter, :embedded => true

    link :self do |opts|
        patient_url(self, opts[:doctor_id])
    end

    def appointments(options={})
        Patient.find(self).appointments.where(doctor_id: options[:doctor_id])
    end
end

Or is there another way I should be doing this?

from representable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.