<%- unless omit_comments? -%>
# ApplicationResource is similar to ApplicationRecord - a base class that
# holds configuration/methods for subclasses.
# All Resources should inherit from ApplicationResource.
<%- end -%>
class ApplicationResource < Graphiti::Resource
  <%- unless omit_comments? -%>
  # Use the ActiveRecord Adapter for all subclasses.
  # Subclasses can still override this default.
  <%- end -%>
  self.abstract_class = true
  self.adapter = Graphiti::Adapters::ActiveRecord
  self.base_url = Rails.application.routes.default_url_options[:host]
  self.endpoint_namespace = '<%= api_namespace %>'


  def self.default_attributes
    klass = self.to_s.gsub(/Resource$/,"").constantize
    klass.columns.each do |c|
      attribute c.name.to_sym, c.type
    end
  end
end

<%- unless omit_comments? -%>
# ApplicationResource is similar to ApplicationRecord - a base class that
# holds configuration/methods for subclasses.
# All Resources should inherit from ApplicationResource.
<%- end -%>
class ApplicationResource < Graphiti::Resource
  <%- unless omit_comments? -%>
  # Use the ActiveRecord Adapter for all subclasses.
  # Subclasses can still override this default.
  <%- end -%>
  self.abstract_class = true
  self.adapter = Graphiti::Adapters::ActiveRecord
  self.base_url = Rails.application.routes.default_url_options[:host]
  self.endpoint_namespace = '<%= api_namespace %>'


  def self.default_attributes(opts = { })
    begin
      unless opts[:from] <= ApplicationRecord
        raise "Unable to set #{self} default_attributes from #{opts[:from]}. #{opts[:from]} must be a kind of ApplicationRecord"
      end
      klass = opts[:from]
      if klass.table_exists?
        klass.columns.each do |c|
          attribute c.name.to_sym, c.type
        end
      end
    rescue => e
      Rails.logger.error e.message
    end
  end
end

Handle errors on class load
Handle errors on class load
