Oops! Rails already has something better than Engines

posted: May 1st, 2008 · by: Sven

in: · tagged as: , , ·  14 comments »

… because it already has Engines for Rails 2.0.

You can file this in the category of “Doh!” and “Things: obvious, but missed” … at least that applies to me. Did you notice it?

I’ve just recognized that with todays Engines and Rails 2.0’s config.plugin_paths you can do exactly what John W. Long envisioned and called for one and a half year ago.

To check that out I’ve reassemled an application that I’m currently working on and that uses Engines to modularize things and added this line to config/environment.rb:


config.plugin_paths << 'vendor/engines'

Now I have a working application with a directory layout like this:


vendor/
  engines/
    adva_blog/
      app/
        controllers/
        helpers/
        models/
        views/
      db/
        migrate/
      init.rb
      routes.rb
    adva_cms/
      ...
    adva_comments/
      ...
    adva_wiki/
      ...
  plugins/
    acts_as_list/
    acts_as_paranoid/
    ...
    will_paginate/

At the same time, the app/ directory is almost empty, because this application is meant as a base or platform for custom applications. Obviously one could move the vendor/engines/ folder somewhere else. Perhaps to apps/ below the app/ directory?.

I totally love this!

But, yeah. Of course this is not exactly the same like what John was talking about. He spoke of first-class sub-apps, i.e. something that’s conceptually on the same level as the Rails “app” itself. With Engines those apps are just plugins.

“Just plugins” in Rails 2.0 means that they are actually very powerful. But there are also some traps with unexpected Depenendcies and class reloading issues that plugins in Rails do not live on the same level as the app. They seem to be meant as framework-level extensions, not application-level extensions.

If Rails would at some point compensate for that, probably by inventing the concept of a dedicated “application-level plugin” that behaves exactly the same way as the application itself does (i.e. reloads in dev mode), … then John’s vision finally would have become real.

Until then, though, I’m super happy to be able to store higher-level Engines separate from lower-level plugins :)

Application-level plugins?

The point is that when it comes to, e.g., using ActiveRecord Observers Rails Dependencies produces errors that can be pretty hard to track when models from plugins are involved. There are other several scenarios like this.

My solution to these issues so far is to put the following line into my plugin’s init.rb file:


Dependencies.load_once_paths -= Dependencies.load_once_paths.select{|path| \
  path =~ %r(^#{File.dirname(__FILE__)}) }  

I haven’t understood Dependencies well enough yet though to be sure if that’s the best way to do have everything in a plugin be reloaded seemlessly with every request in dev mode. But so far it works quite well.

If you happen to know a better solution please let me know!

Maybe it would be a nice idea to wrap that sucker above into a method on Engines::Plugin. Something like: reloadable! and call that from the init.rb file instead.

Leave a comment

14 Comments

  1. court3nay said May 1st, 2008 at 11:50 PM  

    we’re doing some of this in http://github.com/courtenay/tentacle/

  2. Sven said May 2nd, 2008 at 10:19 AM  

    Hi Court3nay!

    Yeah, Rick send me that URL the other day but the project was empty at that point. That stuff looks very interesting! From the first look tentacle seems to have a different focus from this project. I’ll have a closer look asap … maybe we can join forces somehow at some point? Or at least make sure that we can share some engines, probably.

  3. James said May 4th, 2008 at 12:59 AM  

    I tried to post comments to John’s article when he wrote it originally, but they never made it onto his site.

    I’d really love to get some tests that demonstrate the reloading Dependencies problems. Got any ideas? :)

  4. Sven said May 11th, 2008 at 05:55 PM  

    Hi James!

    I’m bad at remembering these things and making definite statements offhand. Your question motivates me to sit down and check out some scenarios. I’ll get back to you as soon as I have something.

    Thanks :)

  5. jack said January 23rd, 2011 at 10:40 AM  

    I tried to post comments to John’s article when he wrote it originally, but they never made it onto his site. cheap vps

  6. Davie Jacob said January 28th, 2011 at 03:25 PM  

    I would say on average, that rails is a bit slower than php. Django is very flexible, dont like the templating engine? las vegas web designers

  7. QQQ said February 7th, 2011 at 06:35 PM  

    Finally we kissed and the passion scale went sky high and I knew I was onto a good thing - sex was a certainty free porn videos. She never hesitated when I began to fondle her breasts and she willingly exposed them for me mobile porn. They were firm and I suspected a breast enhancement but said nothing - they still felt good and I was enjoying them and gradually working my way further south free porn tube. She was a step ahead of me and before I could completely undress her she moved on me atk hairy and I was suddenly having my pants pulled down and I was enjoying one of he best cock sucking hairy pussy experiences I had ever had. ABB728019394

  8. clearprog said March 1st, 2011 at 11:21 PM  

    After reading the post I now think that I will use it for sure. kamagra livraison rapide effexor effexor.

  9. ddsgd said March 21st, 2011 at 06:28 AM  

    How to Convert AVCHD films to AVI

    URL?http://www.wondershare.com/avchd/convert-avchd-to-avi.html Troubles we may possibly have encountered to take satisfaction in and reveal AVCHD films with friends:

    1. You have shot lots of films utilizing AVCHD camcorder, and you also need to upload these films to internet that consist of Youtube to reveal with friends, but you can’t determine the right way to create it.
    2. you could possibly also uncover which you would not possess the ability to available your AVCHD camcorder films on house windows film maker or advertising player.

    That’s true, the AVCHD structure is not accepted by lots of players, and also this kind of structure cannot be uploaded to internet which prevents film sharing. I’ve searched near to some great offer and uncover an simplest alternative finally. The simplest way can be to convert avchd to avi or other standard formats.

    The alternative we are able to consider to solve them: An AVCHD to AVI Converter is needed. Please click to obtain avchd to avi converter, set up and run it. Step one Get AVCHD films from AVCHD Camcorder to PC

    Connect the AVCHD Camcorder for the PC using a USB cable. when attached and powered on, the camcorder should seek out the desktop like a brand brand new disk. It is desirable which you duplicate the films for the PC’s hard-drive earlier to converting avchd to avi or editing it. Step 2. fill AVCHD camcorder videos

    Click “Add Video” or just drag & squirrel away your AVCHD camcorder films using the document checklist directly, you can very easily include AVCHD camcorder videos.

    Load AVCHD camcorder videos Step 3. find AVI as output format

    Select AVI as output structure away from your categorized output formats checklist in “Profile” drop-down checklist and specify the output list to preserve your converted records in “Output” drop-down list.

    Select Convert AVCHD films to AVI output format Step 4. start to convert avchd to avi

    After every little thing is done, strike “Start” key to convert avchd to avi. And all the things can be achieved at quickly demand and higher quality. The conversion demand often is dependent for the genuine film sizing as well as your PC configuration. as well as the output best quality is great.

    After converting avchd to avi, now you can upload these AVI films to internet or view them with house windows advertising Player/Movie Maker to reveal them jointly with your friends. The complete method is easy, and you also can possess a try of the AVCHD to AVI Converter to how to convert avchd to avi and reveal your delighted instant easily.

    Tips: Why we choose AVI format? As we realize that AVI structure is among the probably the most standard formats, that is broadly accepted by the majority of players. as well as the best quality of AVI film is great. using the sake of reputation and compatibility, AVI is regarded as probably the most advantageous choice. Therefore, you only should convert AVCHD to AVI, after which you can very easily reveal your AVCHD camcorder videos.

  10. Raw Food Diet said March 30th, 2011 at 04:10 PM  

    I’m not good at memorizing like these codes, but I’ll bookmark your blog to check this out again.

  11. Cams said March 30th, 2011 at 07:51 PM  

    Dependencies.loadoncepaths -= Dependencies.loadoncepaths.select{|path| \ path =~ %r(^#{File.dirname(FILE)}) }

    The above worked as a fix also.

  12. Okey oyunu said May 12th, 2011 at 03:38 PM  

    Tüm dünya artik okey oyunu oynuyor. Yillardir bir çok oyun programi olmasina ragmen, içlerinden en güzeli olarak nitelendirebilecegimiz tek bir site göze çarpmaktadir. Diger tüm okey oyunu programlarinin aksine ücretsiz olmasi ve 3 boyutlu olarak hizmet vermesi mükemmel bir gelismedir. Sizlerde www. okey-oyunu.com adresinden bu essiz okey oyununu indirebilirsiniz. Kullanimi çok basit ve Türkçe dil seçenegi ile kolaylikla oyuna baslayabilirsiniz. Ister kendi ülkenizden, isterseniz dünyanin tüm farkli bölgelerinden dilediginiz oyun odalarini seçerek, oyuna hemen baslayabilirsiniz. Okey oyunu oynamak için artik arkadas bile aramaniza gerek kalmadan, bilgisayarinizdan 100 binlerce üye ile online olarak okey oyununu oynamanin zevkine varabilirsiniz.

  13. porno said May 23rd, 2011 at 10:36 AM  

    I do agree with all of the ideas you have presented in your post. They’re really convincing and will definitely work. Still, the posts are too short for newbies. Could you please extend them a bit from next time? Thanks for the post

  14. porno said May 23rd, 2011 at 10:37 AM  

    good comment. thanks you friends.

    I’ve surfed the net more than three hours today, however, I haven’t found such useful information. Thanks a lot, it is really useful to me

Sorry, comments are closed for this article.

artweb design
Sven Fuchs
Grünberger Str. 65
10245 Berlin, Germany


http://www.artweb-design.de

Fon +49 (30) 47 98 69 96
Fax +49 (30) 47 98 69 97