Harri Kauhanen’s posterous

Random postings about Ruby, Rails, HTML, CSS, JavaScript and web development/consumer web services in general. 

Problems solved with Charles

I sometimes say: "you are probably not serious about web development if you don't use Charles". What Charles, you may ask. According to the author, Charles is...

"Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information)."

The easiest way to use Charles is to hook it up with Firefox (or any other browser) and start watching what a hell is happening between your browser and the Web. This is not much different from using Firebug's Net inspector. IMHO Charles is slightly better than a plugin, because:

  • The UI works great. If I am only interested in headers, I hide the distractions and display only headers.
  • Filtering. I might have a problem with Ajax requests to a certain site and with a filter I can focus on the problem (not on spotting the right request).
  • You may also debug requests made by Flash components. Your plugin probably does not.
  • I can keep track of the whole session while I travel a site. Plugins usually forget the history as you hit a link leaving the page.
  • You can do little educating tricks with Charles. For instance, slow down the traffic to 3G speed and you might be surprised how (badly) your site works.

This is the way I use Charles 95% of time. But the true power of Charles comes with solving the tricky 5% of problems. Here are some real life examples how I solved a problem with Charles.

I developed a Facebook application with Rails and using Facebooker plugin. I could not save an application box to an user profile. No errors, but no application box either.

I monkeypatched the Facebooker so that I could define a proxy to use when talking to Facebook. Using Charles as a proxy, I realized that Facebooker did not send a parameter that was specified in the Facebook API. Facebook did not return faulty HTTP code. Both ends were buggy, but the problem was solved by fixing the library.

A flash component sent images to server, but images got corrupted every time.

Using Charles I could verify the flash component sent every bit of the data. I also realized it was using a wrong content type "text/html" instead of "image/jpeg". I verified the problem by manually resending the request with Charles, and with the correct mime type. While waiting for the fix from the flash developer, I could keep working as I used Charles to modify mime type for every request on the fly.

I needed to integrate with a complex interface containing multiple steps of SOAP, "raw HTTP" requests, cookie parsing and scraping of HTML meant for humans.

Of course this kind of process will be error prone and customer documentation will be faulty. The problems I encountered were a bit easier to explain to the customer as I could use Charles to capture the traffic and sent capture log the client. The log not only contained the faulty step, but the history of requests before the problem. Charles also validated the SOAP requests I sent, which was useful as I used a "template approach" instead of a "real" SOAP library.

Charles has a home at http://www.charlesproxy.com/

Comments [0]

LOL: My Facebook ad was rejected

My "microblogging" service for Finnish dogs http://haukut.fi had a major defeat today. Our Facebook ad was rejected due "image of this ad is either irrelevant or inappropriate." Yes, I do agree that the picture I used "reveals too much skin" and therefore "is not allowed". Perhaps I should use hairier breeds next time :D

Comments [1]

Retrospective to my old blog

I imported the old blog postings from my self-hosted site to posterous. It was fun to read what I've written.

I haven't found a decent blogging platform yet. Twitter was revolutionary, but posterous and Tumblr are both steps to the right direction (when 140 characters is not enough). 

Rails 3.0 is almost ready, so I guess I don't need to worry about choosing between Rails or Merb.

My ActiveRecord impressions are still the same. Wonderful ORM, might not work with huge applications. My suggestion for namespaced models never saw daylight. But I don't really miss them, because I will not miss relation databases as they will slowly fade away (did you hear me saying a statement or something here... :-)

I still use Fireworks, but really wish I did not have to. It is BUGGY and very unstable under OSX. Really really looking for a killer app outside Adobe camp to resolve graphical needs of web design.

I did not go to RailsConf 2009, because it was never organized. 2008 was fun.

Browser testing is still complex issues and I think I did a good job writing those two articles about the subject. I tend to, however, cope with single real machine or virtual machine having multiple browsers installed simply because switching between versions is so much faster.

My smilies and (improved) coucher are are still in use at http://haukut.fi.

 

Comments [0]

Hello Posterous (bye my old blog)

I realized I hadn't updated my blog for a long time. I also realized that if I'm ever going to blog again, it has to be more lightweight than my customized Mephisto installation. I investigated these options:

After a little testing and tweaking, and reading my old story about choosing a decent blogging platform, I must say I was not much happier now than two years ago. It's year 2010, how hard it can be to embed code from Gist? Or render my code block beautifully? What about importing my old blog? Hello, there's an RSS available. What if I copy/paste text from another source... will the HTML source code fulfill at least some bare minimum semantic standards? Would it remove ugly inline CSS?

No, no, perhaps one yes and no.

But I still wanted to get red of my self-hosted, customized, probably insecure blog. I chose posterous simply because it is:

  • simple enough
  • should be very lightweight to post
  • I hear the search engines do not dislike it

The biggest concern about posterous is... the other posterous blogs. Many of them seem to be just copy/paste articles from the "real blogs". Also I dislike how almost all long articles in Posterous are not accessible. This is probably due the heavy integration with email posting, which simply does not support the concept of "headings".

With short stories posterous seems to work very well. And despite the criticism I just said, it is still a cool concept and very well put service.

Now, will I blog more? What will my posterous postings look like? I really don't know.

Comments [0]

Coucher - Super simple RESTful HTTP service with Rack and CouchFoo

I was learning CouchDB with CouchFoo yesterday. IMHO they are sweet combination and I'm really exited to see how they will mature.

My real task at the moment was, however, to develop a RESTful HTTP service using Rails and as simply as possible. I had some success with Inherited Resources plugin and plain ActiveRecord. I then realized that perhaps having Rails is "too much" for my little service having only a simple XML interface and no HTML based UI or need for session handling. I digged into basics of Rack and suddenly had a great idea. I would only need a Rack aware server, CouchFoo and some Ruby code to implement my RESTful service.

I named it Coucher and here's the code:

Comments [0]

Smileys with Ruby

I needed a simple, preferably accessible, way to add smilies support to one of my projects.

The first challenge was to find nice looking, but free to use, smilies. It was more difficult than you might think, because all the quality smilies I found did not accept commercial usage. Therefore, I ended up creating set of my own 

My original idea was to use a little helper that would markup a given text with smilies a bit. For instance:

This is funny :) This is hilarious :D

The markup'ed version would be:

This is funny <span class="smiley smile">:)</span>
This is hilarious <span class="smiley grin">:D</span>

Then, using one of those CSS image replacement techniques, I would display a graphical smiley and hide the text version.

The first problem I encountered was those techniques seem to work only on block level DOM elements. Smileys, however, should be part of the normal text flow. Another problem was that I could not make the text inside span dissappear and at the same time display a smiley graphics as background. Therefore, I needed another span. I also had to add some content inside the outer span so that Firefox would render it nicely and Internet Explorer would display it at all.

 .smiley {
       background-repeat:no-repeat;
       padding-left: 16px; /* The width of the image */
  }

 .smiley.smile {
     background-image:url(/images/smileys/smile_16.png);
 }

 .smiley.grin {
     background-image:url(/images/smileys/grin_16.png);
 }

 .smiley .smiley-as-text {
     position: fixed;
     top: -500px;
 }

Why did not I just hide the smiley-as-text span? The answer: some screen readers would skip the smiley. To be honest, I don't know how screen readers handle smileys, but by not hiding the span, smilies will at least be read.

Here's the Ruby code I would use in one of my Rails helpers.

SMILEYS = {
  ':)' => 'smile',
  ':-)' => 'smile',
  '=]' => 'smile',
  '=)' => 'smile',
  ';)' => 'wink',
  ';]' => 'wink',
  ';-)' => 'wink'
} # and the rest of the smilies...

def smiley(text)
  SMILEYS.each do |smiley, smiley_class|
    text.gsub!(smiley, "<span class='smiley #{smiley_class}'><span class='smiley-as-text'>#{smiley}</span>&nbsp;</span>")
  end
  return text
end

What if I have varying font sizes and we want to use smilies that scales with the text size. Well, my solution is to create smileys for the each font size. E.g. wink_16.png would work well with 16px fonts. We do not need not to touch the Ruby helper at all. Instead, we handle smiley sizes using CSS and simply wrap the the text with a new class, for instance <div class='big-text'>This blog entry is about to end :(</div>.

.big-text {
    font-size: 24px;
}

.big-text .smiley {
    padding-left: 24px;
}

.big-text .smiley.sad {
    background-image:url(/images/smileys/sad_24.png);
}

Comments [0]

Browser testing with virtual machines

This is the promised follow-up to my previous blog post. So, how I do the browser testing myself using OSX and VMware Fusion. In short, the process is:

  • Install a clean Windows XP
  • Configure “minimal settings” to the virtual machine
  • Copy three new virtual machines titled:
    • Legacy Browsers
    • Modern Browsers
    • Future Browsers
  • Install multiple browsers to each of these new virtual machines
  • Clean up the OS, browser caches etc.
  • Take a virtual machine snapshot (to return to a clean state anytime)
  • Install Linux using the same procedure

Install Windows XP and configure virtual machine

Some hints:

  • If you don’t need USB, disable it (you will not get annoying Windows notifications whenever you connect your devices)
  • You might want to enable printers, if you need to test the printing of your site
  • You probably don’t need much disk space (VMware Fusion is smart and actually spends the used amount of disk space!)

Copy virtual machines for browsers

With Fusion, you simply copy the existing virtual machine file and open it. You should cope with two or three virtual Windows instances. You do not want to create a new VM for every browser, because you will run out of disc space and CPU resources trying to run them parallel. Here’s my set up:

  • Legacy Browsers
    • Internet Explorer 6
    • Firefox 2
    • Opera 8.5
    • Java 1.4 (consider an older version!)
    • Flash 8
    • ClearType fonts disabled (as global Windows setting)
  • Modern Browsers
    • Internet Explorer 7
    • Firefox 3
    • Opera 9
    • Chrome
    • Java 6
    • Flash 9
    • ClearType enabled
  • Future Browsers
    • Internet Explorer 8
    • Firefox 3.1
    • Opera 9.6
    • Java 7
    • Flash 10

Where’s Safari? Well, I don’t need a virtual machine for Safari as I can use well working “standalone” version on my OSX (actually, Opera can be tested on OSX similarly). See details at my ultimate guide to browser testing article. You will also find download links to the software listed.

Clean up and take a snapshot

VMware Fusion (as well as many other VM solutions) support snapshots. Whatever I do within my testing sessions, I can easily return to a clean starting point. Before taking the snapshot, I…

  • clean up browser caches
  • tidy up desktop and Start-menu

Finalizing touches

If your browser testing is in active phase, you might want easier access to the browsers. With Fusion you can use a “coherence” mode so that the windows of Windows look just like any other app running on your mac. I even created a dedicated dock for my browsers and I can easily switch using Dock Spaces.

Comments [2]

An ultimate guide to browser testing

So you created the coolest site on planet, and want to make sure it works on all web browsers and every configuration possible. Just download all the released versions of all the web browsers you know, spend some time installing and begin testing…

But hey, do I really need to install all those browsers/versions? And test with JavaScript on/off? Flash? Screen sizes? Well, if you absolutely want to make sure your site works in every possible browser configuration on planet, the answer is unfortunate yes. But if you are smart, you do a little research, create an appropriate browser testing setup, test your site and expect it to work 99.9% times.

Ingredients

The ingredients for the successful browser testing are:

  • knowledge of layout engines and browsers
  • official and unofficial browser packages
  • de-facto rendering add-ons
  • useful browser plug-ins
  • web-based testing tools
  • multiple operating systems
  • a virtual machine player

Let’s have a look on each ingredient in detail.

Layout engines and browsers

Under the hoods of every browser is a layout engine that does the hard work of rendering your HTML/CSS/JavaScript into something visual. There are many more browsers than engines, and from the testing point of view, you should make sure all the major engines are covered in your tests.

Each engine has a long history and comes with number of versions. Is there any recommendations about what engines and versions I should pick for my testing setup? One of the most referenced one is Yahoo’s Graded Browser Support. Unfortunately, it does not say a word about layout engines, but you can easily catch up by checking out the List of layout engines. The point is; knowing browser engines give you confidence that if you test something with browser X, it will very likely work well in browser Y. In other words, there might be little reasons to test a site with both browsers X and Y, if they use the same layout engine.

You should also follow the browser statistics of your own site. Use a log analyzer such as AWStats or statistics collector such as Google Analytics. Needing someone else’s word on it, Browser Version Market Share or W3School’s Browser Statistics are good sources to refer.

If all this sounds too complex to dig into, here’s some details of the most popular engines and browser recommendations.

Trident

Internet Explorer uses a proprietary (Trident) engine. There are currently three major versions of IE on the market – all using heavily rewritten layout engine. Unfortunately IE versions tend to stay on the market for quite long time. My recommendation is to test carefully with IE 7 and keep IE 6 on your list – especially if you are providing a consumer service. As IE 8 hits the official release, be prepared to add it to your testing setup.

Gecko

Gecko is popular engine among open source web browsers, and used in Firefox. Firefox users tend to upgrade their browsers much quicker that Internet Explorer users. You probably play quite safe by testing with the latest major version number, and one generation backwards. Currently it means Firefox 3.1 and Firefox 2.0. Firefox is popular in all operating systems. Therefore, it is great for testing how differently Windows, OSX and Linux versions render your site.

WebKit

Safari is the most well known web browser using WebKit engine. WebKit is also becoming very popular among open source browser projects. The engine is surely popular enough to include in your testing setup, but testing with the latest version of Safari or Google Chrome is probably enough. iPhone, Nokia smartphones and many other handhelds use WebKit engine as well. If you definitely need to make sure your site renders perfectly on a device, you should test the site with a real thing or a device simulator.

Presto

Opera browser uses an engine called Presto, and the engine is used by some niche devices as well. I recommended doing occasional testing with the latest Opera version. Presto engine is very accurate and standard respecting. Therefore, do I dare to say, your site is likely to work well on Presto, if it works well on a Gecko or WebKit based browser.

Other engines

I also recommend occasional testing using one of the text-based browsers such as ELinks. It is an easy (but incomplete) accessibility simulator and reveals the missing HTML semantics.

Browser packages

Installing multiple browser brands into your OS isn’t usually a big hazzle. Perhaps you will witness a tiny non-bloody fight whether Firefox, Opera or Safari shall be the default browser in your system. On the other hand, running multiple versions of a single brand of browser is often tricky, sometimes terribly hard. It’s not too hard to guess that Internet Explorer is the enemy of web developer in this territory too, but other browsers, such as Firefox and Safari, aren’t really your friends either. But hey, let’s stop mocking and get the job done.

Internet Explorer

Internet Explorer is tightly tied to the Windows operating system. Don’t expect to install any version of IE without updating some “system DLLs” and a reboot. Therefore, running multiple versions of Internet Explorer is very hard. Even worse, you cannot officially test drive the forthcoming IE 8 without removing IE 7. The official Microsoft solution is to use special virtual machine images. The problem with these images is they are only provided in Virtual PC format, they expire within couple of months and they are sometimes buggy (the virtual machines, not the browsers). If this is your way to go, there are instructions on how to convert images to other virtualization formats.

Somewhat more convenient solution is to use unofficial “standalone” IE 7 and Multiple IE packages. Don’t expect these to work perfectly. They might e.g. have broken bookmarking or occasional crashing, but rendering engines should be accurate. An interesting alternative is the IETester in which you can test multiple IE versions at the same time on shared screen.

Microsoft offers the “normal” versions of Internet Explorer 6, Internet Explorer 7 and Internet Explorer 8 on their website. Older versions are found at Old App’s Internet Explorer archive.

Firefox

Installing multiple Firefoxes is not hard, but it is a bit cumbersome to keep those instances not messing up each other. There are many guides how to manage it. Mac users might be happier using MultiFirefox doing all the dirty work for you.

The official Firefox site provides downloads to the latest Firefox 3.0 version and officially supported Firefox 2.0. The “next generation” Firefox is always developed under a codename and 3.1 is called “Shiretoko”. The latest build should be found somewhere in Firefox Releases archive. Older versions are found at Old App’s Internet Explorer archive. The Mac archive misses quite many versions.

Safari

Forthcoming version of Safari (4.0) can be installed without conflicts side-by-side with the existing Safari browser via WebKit nightly builds. Unfortunately, this is not so easy with the older Safari releases. Multi-Safari is to rescue (Mac users) providing well working standalone versions of Safari.

Official releases on Apple’s site are Safari 3.1 and Safari 2.0, and the older versions are found at Old App’s Internet Safari archive.

Opera

It seems Opera has least problems running multiple versions side-by-side. I have had no problems installing any version of Opera and running them simultaneously on my Mac. Opera provides comprehensive collection of browser versions at Opera archive.

Mobile browsers

Despite most mobile browsers use the same engine than Safari does, the screen size limitations and smart zooming/scaling features almost enforce proper testing with a real device. If you don’t have one or testing is difficult due networking problems, you will manage with the device simulators.

iPhone simulator (on Mac) is bundled with iPhone SDK. Remember that you don’t need the install the full development kit. Just locate the simulator image, and install from there. A decent Nokia phone simulator (for Windows) can be found inside S60 SDK. Again, don’t install it all – just select the simulator from the installation options.

Text based browsers

There are a number of text based browsers out there and you’ll find good hints and links to actual browsers at Site Testing with Text Based Browsers.

De-facto rendering add-ons

Not everything you see on a web page is always rendered by the browser’s engine.

Flash

According to Adobe’s Flash penetration statistics, you could say almost all browsers now have a Flash player installed. On the other hand, most mobile devices do not play Flash at all. All the Windows versions of Flash player can be downloaded at Adobe’s Archived Flash Players.

Java

I could not find good penetration statistics for Java in browsers, but Java vs. Flash gives you a clear impression that Java is much less popular. But if your site has Java applets, you could test it with different Java versions. Sun provides comprehensive Java archive for all the versions ever released.

Browser plug-ins

There are tons of helpful plugins for Firefox and certainly good ones for other major browsers as well. From the testing point of view, let’s have a quick look on two essential plug-ins.

NoScript

NoScript is a popular Firefox plugin for blocking JavaScript, Java and/or Flash. You might not want to use it in your daily web browsing (or you do), but it certainly is an excellent tool for testing how your site behaves when users cannot view all your content. For instance, according to W3School’s Browser Statistics, in January 2008 JavaScript was not enabled for 5% of the web surfers.

Web Developer

If you are a developer, you are likely to use excellent Web Developer toolbar for Firefox. It is also great for testing your site e.g. without stylesheets or cookies, and testing the various screen sizes. Example resources of screen size stats are Market Share’s Screen Resolution and W3School’s Browser Display Statistics.

Web-based testing tools

No surprise, you can find interesting web browser testing tools in the web.

Browsershots

Browsershots is a wonderful tool to test rendering of your (public) site with a number of browsers in different operating systems. If you are in a hurry, you can pay for priority rendering.

BrowserCam

An advanced web-based tool for browser testing is BrowserCam. In addition to browser screenshots, with a paid plan you can get shots from mobile devices or have remote access to real browsers. I did not test this in practice, but it sounds very cool, if remoting works fast enough over the network.

Operating systems

Some popular browsers can be installed to multiple operating systems. For instance, Firefox is available to almost any platform. The rendering results, however, are never pixel-to-pixel same. The colors can look surprisingly different and text may have totally different typefaces. Even the operating system settings influence on the rendering results. For instance, some Windows fonts look really ugly without ClearType turned on.

An obvious solution for cross-platform testing is to have multiple testing computers or a single multi-booting computer with multiple operating systems installed. Using a virtual machine, however, might be far better solution.

Virtual machine players

With a virtual machine player you can e.g. run Windows while using Mac OSX. The major benefit of having a virtual machine instead of running a “real one” is that you can create multiple setups of a single OS. For instance, you could have one setup for running IE 6 and another for IE 7. Even greater, some players support “snapshots” providing an easy way to reset your system to a clean state, if you messed up something. In addition, testing becomes more streamlined when you use a virtual machine, if the option is to reboot your computer between the testing cycles.

These are the most well known virtual machine players:

An alternative VM technology for running Windows apps is Wine. With some work (and good luck) you may get a Windows app running “natively” in your Linux or OSX. There are instructions on running Internet Explorer on Wine and some helper scripts such as IEs 4 Linux.

Browser testing setups

So, how should I test my site? Well, it depends :-) If your needs are “light”, I would suggest a light solution. You could, for instance, simply use Windows with those unofficial “standalone” browser packages, and use a web-based service for checking the rendering under other operating systems. If you are building the next Facebook, I would certainly install a good virtual machine solution for each developer and a testing center with multiple PCs to the test-only guys.

My solution is somewhat “semi-hardcore” and requires quite a lot of preliminary work. Once you get it running, however, it is quite a pleasure to use. It consists of a VM player supporting snapshots. I have three Windows images titled “Legacy Browsers”, “Modern Browsers” and “Future Browsers”. Each image contains the most popular browser of each layout engine, but there are only one version of each browser brand. I also use older Flash and Java versions in the Legacy Browsers image, and beta versions in Future Browsers. WebKit testing I like to do with unofficial standalone Safari packages and I use multiple Firefox profiles for “feature X ON/OFF” testing.

I will post a follow-up about the details of my setup within my next post. In a meanwhile, happy testing!

Comments [3]

RailsConfEurope 2008

Sitting back in the balcony of my Hotel Room and enjoying a bottle of Berliner Kindl. While I’m still here, and everything is still fresh in my memory, why not writing a report about the conference.

I have an advantage over many other participant by being relatively new to Rails and attending RailsConf for the first time. Therefore, I had “pair of fresh eyes” and I could get at least something out of every presentation I saw.

David’s keynote about “legacy software” was not one of the most enthusiastic ones, but it indeed was inspiring and gave me good reasons to be even more proud about the legacy code I’ve written during the years. Jeremy Kemper’s keynote about performance was a very good overview about “real performance” end-users experience when using web services. It also promised a slightly better performance in Rails 2.2 and some performance tools to play with.

Tutorials on Tuesday felt a little too much too long presentations. I would have hoped more hands-on exercises with more intimate feeling and personal assistance. Perhaps the organizers should limit the number of seats next time. The session about “resourceful plugins” was actually a tutorial about how to write good plugins. I’ve never written a plugin, so it was helpful for me. The afternoon session about deploying and monitoring Rails apps had more hands-on work, but network problems impaired the exercise a bit. The presentation itself was very clear, but could have gone more to the details (time should not have been a limiting factor here).

The two jQuery related presentations on Tuesday morning were interesting, but the one about unobtrusive scripting was definitely more helpful. Intellectual scalability introduced a very interesting solution to write complex write applications. The “JavaScript requirement”, however, was something I could not buy in my personal projects. The ResourcefulViews plugin introduced in Restful everything seemed very useful. I have always problems to remember how Rails links and forms are generated, but this baby could be the cure. Hopefully something like this will end up to the Rails core one day. A talk about Security on Rails was very clear and well presented, but perhaps the content was a little too basic for RailsConf.

My Thursday morning started with Design on Rails for usability. IMHO it wasn’t about too much about Rails nor usability, but nevertheless it made some very good points about creative design process. Starling+Workling presentation was one of the more entertaining ones. Internationalization is officially coming to Rails, and that’s good news! From Rails security to application security introduced a very promising plugin called declaritive_authorization (not available yet?). I think the audience did not fully get the (splendid) message, because the presentation was perhaps a bit too academic. I would have wished How not to build a service was a bit more “juicy” one. One of the personally most useful presentations was Future is video. It was also very well structured and presented – a very nice finale to the conference.

The best thing about the Wednesday/Thursday presentations was that they were quite short. You should easily be able to concentrate the 40 given minutes, and on the other hand, it clearly made the authors think beforehand what to say, and how to organize the presentation. If I’ve got something to complain about, some presentation titles were somewhat misleading. The presentation description should also contain a word or two about “skill level” required.

I was a bit afraid the conference would have a little too fanatic “Rails is fucking awesome” atmosphere, but it turned out to be quite relaxed and down-to-earth, instead. My humble hint to the organizers is that try to keep RailsConf “advanced” (more advanced) and perhaps start organizing “mainstream” Rails events locally in Spain, Finland, Netherlands etc. And Rails is slowly but surely becoming mainstream, don’t you agree?!

Will I attend next year? Maybe. Overall, I’m happy that I did go the RailsConf Europe 2008, and I surely learned a lot. Many thanks to anyone involved!

Comments [1]

Namespaced models in Rails

“Rails does not scale”.

I now have some experience writing software with Rails. I do not believe well written Rails apps would have particular problems to scale up in terms of number of people using the app. Application size, however, seems to be somewhat difficult scale up with Rails. If your app is a bit more complex one, and require lot of model classes, you will likely have problems to keep your app well organized. You might e.g. have hundred classes or fixture files under one directory. You might also have problems with limited namespace and end up using long and ugly looking class names.

Ruby support namespaces and organizing apps using modules. Rails has an assorted support for namespaces. For instance, ActionPack supports namespaces well. On the model side the support has been somewhat vague, but it seems Rails 2.1 and especially the lates Edge Rails support namespaces in ActiveRecord quite well. I don’t hear any praise about this great development in the Rails community, but for me, this is great news. Namespaces not only keep me organized and allow sensible class names, they naturally facilitate writing a better architecture and a bit more modular code. There are some workarounds there, but I really think true and complete support for namespaces would indeed be useful.

My personal project is still very much under development, and I use Rails generators lot. And I am using those namespaces in my models. Therefore I decided to tune Rails generators to support namespaces as well. Now I can:

script/generate scaffold Animal::Dog name:string gender:string

This will generate model, controller and views so that you can access them by:

http://localhost:3000/animal/dogs

It also generated working tests and a fixture file, all well orgnized under folders names “animal”.

I also changed the naming convention of database names so that namespaced model will be prefixed using the module name (e.g. animal_dog).

I created a ticket to Rails Lighthouse including my patch. I think this is very cool (even hot) stuff, but not seeing too many comments yet. Do give it a try and let me know what you think.

Comments [0]