ruby on rails - Nested Objects with Inherited Resources -


first off, love inherited_resources

consider following:

class job < activerecord::base   has_many :inputs, dependent: :destroy   has_one :output end  class jobscontroller < inheritedresources::base   respond_to :json end 

when request jobs/1.json json of job object. want inputs , output included. achieve by:

job.to_json(include: [:inputs,:output])

my question best way achieve ir? now, i'll overwrite show, wanted know if there more elegant way?

thanks!

@corroded put me on right track. answer overwrite as_json on model.

specifically did following:

  public    def as_json(options={})     super(include: [:inputs,:output])   end 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -