Hi,

I have a question regarding to extend a subclass from an abstract class.

Suppose I have an abstract class which has 3 properties in the table:

// event.rb
class Event < ActiveRecord::Base
self.abstract_class = true
end

// event migration
class CreateEvents < ActiveRecord::Migration
def change
create_table :events do |t|
t.string :name
t.string :address
t.string :telephoneNumber

t.timestamps
end
end
end

If I want to extend this class from this event class, say a Party class:

// party.rb
class Party < Event
end

and it has 1 properties in its own party table.

My question is that is there a way in Rails so that I can carry those 3
properties from the Event class to the Party class?

The problem is that I don't know how to carry out the parent properties
to the child class automatically. Or do I need to type all the parent
properties everytime I need to extend from the abstract class (this
sounds painful...)

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@googlegroups.com.
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.

Search Discussions

  • Frederick Cheung at Dec 9, 2011 at 10:30 am

    On Dec 9, 6:07 am, "kahou l." wrote:
    Hi,
    If I want to extend this class from this event class, say a Party class:

    // party.rb
    class Party < Event
    end

    and it has 1 properties in its own party table.

    My question is that is there a way in Rails so that I can carry those 3
    properties from the Event class to the Party class?

    The problem is that I don't know how to carry out the parent properties
    to the child class automatically. Or do I need to type all the parent
    properties everytime I need to extend from the abstract class (this
    sounds painful...)
    You have a few choices:
    - if you do use an abstract class then yes, for each subclass you'll
    need to create the table for the subclass
    - you could switch to single table inheritance: all the subclasses
    share the same table
    - maybe you don't want inheritance at all, e.g. maybe your various
    classes should belong_to some common model

    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@googlegroups.com.
    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.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedDec 9, '11 at 6:08a
activeDec 9, '11 at 10:30a
posts2
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Kahou l.: 1 post Frederick Cheung: 1 post

People

Translate

site design / logo © 2022 Grokbase