0

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.

bdx
  • 3,316
  • 4
  • 32
  • 65

1 Answers1

0

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

Billy Chan
  • 24,625
  • 4
  • 52
  • 68
  • I don't want there to be a `Service` table now or ever - I just want `MiscService` and any other services I define in future to inherit all the methods from `Service` while using their own tables all of which will have unique schemas. – bdx Mar 13 '14 at 03:17
  • If you want methods only, use module and include/extend them, and then models will act like service. Do not use inherits. – Billy Chan Mar 13 '14 at 03:21
  • That seems very sensible. Thanks – bdx Mar 13 '14 at 03:41