Include associated model when rendering JSON in Rails
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?
Solution 1:
Something like this should work:
render :json => @programs, :include => {:insurer => {:only => :name}}, :except => [:created_at, :updated_at]
Solution 2:
i was getting the same "can't clone Symbol file" error while rendering json with includes from a controller method. avoided it like so:
render :json => @list.to_json( :include => [:tasks] )