Include associated model when rendering JSON in Rails
json, ruby-on-rails
Solution
Something like this should work:
render :json => @programs, :include => {:insurer => {:only => :name}}, :except => [:created_at, :updated_at]
Problem
Right now I have this line: ``` render json: @programs, :except => [:created_at, :updated_at] ``` However, since a Program belongs_to a Company I would like to show the Company name instead of the Company Id. How can I include the company name when rendering Programs?