Hi, I was trying to create an abstract class and a subclass which
inherit that abstract class.
However, seems like I cannot instantiate the subclass too. Below is my
code:
//abstractclass2.rb
class Abstractclass2 < ActiveRecord::Base
self.abstract_class = true
end
//subclass.rb
class Subclass < Abstractclass2
end
When I test drive it in rails console, I got the following error:
from (irb):1irb(main):002:0> sb = Subclass.new
ActiveRecord::StatementInvalid: Could not find table
''subclasses''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:439:in
`table_structure''
from
/usr/lib/ruby/gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection_adapters/sqlite_adapter.rb:322:in
`columns''
If I take out "self.abstract_class", everything works fine (subclass
object is inserted into abstractclass table but abstractclass can be
instantiated --> that''s not what I want to...)
Did I miss something here so that I cannot instantiate the subclass?
Thanks,
Kahou
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On Dec 3, 6:55 pm, "kahou l." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> When I test drive it in rails console, I got the following error: > > from (irb):1irb(main):002:0> sb = Subclass.new > ActiveRecord::StatementInvalid: Could not find table ''subclasses'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection _adapters/sqlite_adapter.rb:439:in > `table_structure'' > from > /usr/lib/ruby/gems/1.8/gems/activerecord-3.1.3/lib/active_record/connection _adapters/sqlite_adapter.rb:322:in > `columns'' > > If I take out "self.abstract_class", everything works fine (subclass > object is inserted into abstractclass table but abstractclass can be > instantiated --> that''s not what I want to...) > > Did I miss something here so that I cannot instantiate the subclass? >In the setup you''ve described, rails expects the subclass to have its own table. If you don''t want that, then don''t set abstract_class to true Fred> Thanks, > Kahou > > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.