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
Post a Comment