Modules in rails? ( controllers or models?)

Discussion in 'Ruby' started by malugu satyajit, Dec 2, 2007.

  1. Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    Hello,

    I have an rails application that has almost similar function for three
    classes. So I am thinking to create a parent class and then the sub classes
    inherit from it. But rails already inherits from ActiveRecord(models) or
    ApplicationController(controller).

    So how can I inherit from others classes. My my ruby knowledge it is modules
    and then you mixin the module in your class.

    Now my question, where you write the module in rails is it in controller or
    model? Can some one provide me links or guidance.


    --
    Regards,
    M.Satyajit
    Graduate Student,
    Department of Computer Science,
    NCSU.
    www4.ncsu.edu/~smalugu
     
    malugu satyajit, Dec 2, 2007
    #1
    1. Advertising

  2. malugu satyajit

    thefed Guest

    On Dec 2, 2007, at 6:40 PM, malugu satyajit wrote:

    > Hello,
    >
    > I have an rails application that has almost similar function for three
    > classes. So I am thinking to create a parent class and then the sub
    > classes
    > inherit from it. But rails already inherits from ActiveRecord
    > (models) or
    > ApplicationController(controller).
    >
    > So how can I inherit from others classes. My my ruby knowledge it
    > is modules
    > and then you mixin the module in your class.
    >
    > Now my question, where you write the module in rails is it in
    > controller or
    > model? Can some one provide me links or guidance.
    >


    You can create a parent class that inherits from ActiveRecord or
    ApplicationController.
    Then, your subclasses can inherit from the parent class.

    This may or may not work, and this is a question for the rails list


    _______________________________|
    - Ari
    I just bought another case of RockStar. Expect architectural changes.
     
    thefed, Dec 2, 2007
    #2
    1. Advertising

  3. Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    thanks... can you say the rails list address? I found it on web.. but just
    be sure

    On Dec 2, 2007 6:49 PM, thefed <> wrote:

    >
    > On Dec 2, 2007, at 6:40 PM, malugu satyajit wrote:
    >
    > > Hello,
    > >
    > > I have an rails application that has almost similar function for three
    > > classes. So I am thinking to create a parent class and then the sub
    > > classes
    > > inherit from it. But rails already inherits from ActiveRecord
    > > (models) or
    > > ApplicationController(controller).
    > >
    > > So how can I inherit from others classes. My my ruby knowledge it
    > > is modules
    > > and then you mixin the module in your class.
    > >
    > > Now my question, where you write the module in rails is it in
    > > controller or
    > > model? Can some one provide me links or guidance.
    > >

    >
    > You can create a parent class that inherits from ActiveRecord or
    > ApplicationController.
    > Then, your subclasses can inherit from the parent class.
    >
    > This may or may not work, and this is a question for the rails list
    >
    >
    > _______________________________|
    > - Ari
    > I just bought another case of RockStar. Expect architectural changes.
    >
    >
    >
    >



    --
    Regards,
    M.Satyajit
    Graduate Student,
    Department of Computer Science,
    NCSU.
    www4.ncsu.edu/~smalugu
     
    malugu satyajit, Dec 2, 2007
    #3
  4. malugu satyajit

    Todd Benson Guest

    On Dec 2, 2007 5:40 PM, malugu satyajit <> wrote:
    > Hello,
    >
    > I have an rails application that has almost similar function for three
    > classes. So I am thinking to create a parent class and then the sub classes
    > inherit from it. But rails already inherits from ActiveRecord(models) or
    > ApplicationController(controller).
    >
    > So how can I inherit from others classes. My my ruby knowledge it is modules
    > and then you mixin the module in your class.
    >
    > Now my question, where you write the module in rails is it in controller or
    > model? Can some one provide me links or guidance.


    Well, from a kindergartener's perspective (namely, mine), I would
    think that if your classes represent tuples of data in a database,
    they would be models, and you would add functionality by having the
    model classes (those that inherit from ActiveRecord::Base) require the
    necessary mixin themselves, or make use of #extend. I think, however,
    it is highly dependent on your situation.

    I'm sure you can find some best practices advice from the rails list.
    The one I have bookmarked is:
    http://groups.google.com/group/rubyonrails-talk.

    Todd
     
    Todd Benson, Dec 3, 2007
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. vinjvinj
    Replies:
    15
    Views:
    585
    Jeremy Sanders
    Nov 10, 2005
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    441
    Jean-Paul Calderone
    Nov 7, 2005
  3. David Heinemeier Hansson
    Replies:
    0
    Views:
    238
    David Heinemeier Hansson
    Dec 23, 2004
  4. BearItAll

    Rails validate in models

    BearItAll, Sep 5, 2005, in forum: Ruby
    Replies:
    2
    Views:
    136
    BearItAll
    Sep 5, 2005
  5. Kev
    Replies:
    6
    Views:
    179
    Carl Lerche
    Nov 12, 2006
Loading...

Share This Page