Domanda

I have a generic Service model which contains a few generic functions including a few to be overridden by 'actual services'.

service.rb

class Service < ActiveRecord::Base
  def get_line_items
    raise "Not Implemented"
  end
end

I then have a model extending the Service model:

misc_service.rb

class MiscService < Service
  attr_accessible :retail_price
  def get_line_items
    return [{"Misc Service - 1" => retail_price}]
  end
end

However, when trying to access the MiscService model in the rails console, I'm getting the error:

:001 > service = MiscService.first
ActiveRecord::StatementInvalid: Mysql2::Error: Table 'devdb.services' doesn't exist: SHOW FULL FIELDS FROM `services`

I can see that's happening because it's the Service model extending ActiveRecord::Base, so is there something I can do in the Service model to cause any models extending it to instead use their own table? I'd prefer to have that happen from the Service model and not have to explicitly define it in any models extending it.

È stato utile?

Soluzione

This has nothing to do with sub classes. Your service table itself isn't ready. Make sure you have migration file ready and run $ rake db migrate

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top