Return multiple includes on object Ruby on Rails JSON -


i have 3 models , trying output of them json in single object.

the models , associations follows:

class customer < applicationrecord   has_one :subscription   has_one :address end  class address < applicationrecord   belongs_to :customer end  class subscription < applicationrecord   belongs_to :customer end 

i trying return of associated data json using following:

class homecontroller < applicationcontroller   def index     @customers = customer.all     render json: @customers, :include => :address, :subscription   end end 

however returning syntax error ruby expecting => somewhere. on how can output of data appreciated.

incase looking i've answered question following syntax.

class homecontroller < applicationcontroller   def index     @customers = customer.all     render json: @customers, :include => [:address, :subscription]   end end 

address , subscription needed passed in array :)


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -