SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Cool Re-use code for new Rails app

    Hi,
    I have recently completed my first rails app (yay!), and now I'm starting my second one. I'm also starting to realise that I can simply re-use a lot of the code I've written for the first app. But what's the best way to do that. Right now I just copy e.g. the LoginController from my first app and paste it into my second app. That's silly, isn't it? Because it breaks with Rails' DRY principle. What do you say?

  2. #2
    SitePoint Guru CompiledMonkey's Avatar
    Join Date
    Sep 2002
    Location
    Richmond, VA
    Posts
    975
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kind of off topic, but what did your first application do? How complex was it for a first application in a new platform?

  3. #3
    SitePoint Evangelist Pixelateur's Avatar
    Join Date
    Feb 2006
    Location
    Hamburg, Germany
    Posts
    592
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My first app was a simple e-commerce site, with a custom-made CMS behind the scenes: UKAutobarn.com. I have only partly adjusted it for IE6, so it's best viewed in Mozilla or Safari.

    I think I won't re-use any components from my first app in my second one, because it might get too complex in the end and does not allow for too much customisation. I will re-use the stylesheet for the CMS from app 1 though...

  4. #4
    SitePoint Member
    Join Date
    Nov 2006
    Location
    Austin, TX
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    refactor the common code into a module and include it in your second project via the lib dir

  5. #5
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Or consider extracting to a plugin.

  6. #6
    SitePoint Guru Majglow's Avatar
    Join Date
    Aug 1999
    Location
    B-Town
    Posts
    645
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    rails engines.
    Ohai!

  7. #7
    SitePoint Guru silver trophy Luke Redpath's Avatar
    Join Date
    Mar 2003
    Location
    London
    Posts
    794
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Majglow
    rails engines.
    Are generally overkill.

  8. #8
    SitePoint Enthusiast HeshamAmiri's Avatar
    Join Date
    Oct 2003
    Location
    Dubai
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wouldn't use engines either...and it seems alot of RoR community members are somewhat unsure if whether it is a goof idea as well.

  9. #9
    SitePoint Addict
    Join Date
    Mar 2004
    Location
    Grand Junction, CO
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought Engines were a very good idea when they first came out. Then I started using them, and, well, I don't use them anymore

    The best thing to do is refactor your code out into a plugin. Any time you'll be reusing or duplicating code it's probably a good candidate for a plugin. App-specific code is usually a bit grittier...but fortunately there's been some recent discussion in the Rails community about this sort of thing. Okay not really discussion, but more like a couple guys telling everyone how they solved the problem Check out http://www.pluginaweek.org which is a new blog where these guys talk about a bunch of plugins they wrote. One of them that will come in handy for you is the just-announced appable_plugins, which lets you share model, helper, and controller code through apps. It solves my two key gripes with Engines: Engines can't share model code easily, and Engines are just pretty heavy over all.

    I'm excited about that blog, I think we'll get lots of cool stuff from them in the coming months.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •