• Shortcuts : 'n' next unread feed - 'p' previous unread feed • Styles : 1 2
aA :  -   +

Date: Friday, 28 Oct 2005 02:50

I am happy to make the official announcement that fellow rubyists and Thoughtworkers Obie Fernandez and Carlos Villela (Brazil!) are the new maintainers of the acts_as_taggable mixin. Both are very active in the Ruby & Rails community and outstanding coders as well. Finally, they’re also very nice guys. ;-)

I want to thank all of you who volunteered to take my place in keeping the taggable thing rollin’.

I must say that I am very confident in leaving my little contribution to the Rails community in such competent hands.

I’ve already passed on to them all code, requests, suggestions and contributions from acts_as_taggable users out there and they’re organizing to get things moving once again.

It’s also nice to see that the acts_as_taggable gem has now been downloaded more than 460 times. Keep it up Obie and Carlos! I know you will. ;-)

Author: "--" Tags: "Rails"

Date: Thursday, 20 Oct 2005 02:58

Over a month without posting usually means something really big happened on the life of a blogger. Maybe I got hit by a bus and am writing this from my celestial notebook, but no, not yet.

This will sound a bit shocking to my fellow readers and core hackers out there, so I’ll tell you at once: I took a management job.

And this will sound even more outrageous: I am enjoying it!

In the past, as the CIO/CTO of my own start-up, I frequently alternated between management and hacking depending on the current size of our team and our development needs. So, I’ve always had a great deal of interest in getting good at management. Peopleware is my bible on that area and since I’ve read it, I see good managers much more as team motivators and facilitators than bosses. I’ve also just got Ship It! and Behind Closed Doors, a excellent software management combo from the pragmatic guys.

Anyway, there’s a LOT to be done in the company that I am working now. We’ve got great human material there and I am truly excited in seeing those folks really shine once we get things rolling smoothly.

And that kinda of explains why time has been such a precious (and scarce) thing for me in these last weeks.

To conclude this part, do expect some software management articles on Y.o.m.b.a.r. from now on.

Now, let’s talk about Rails, shall we?

I was really, really happy to see the release notes for Rails 1.0 Release Candidate, for mainly 2 reasons:

First, while there are, undoubtly, some huge improvements in the upcoming 1.0, there’s not that many functionality additions, and that’s a GOOD THING. It confirms that Rails is rapidly maturing and at the same time not falling for the ‘featuritis crisis’, which doomed several other well known web frameworks out there. 1.0 is mostly about internal restructuring, bug fixing and small improvements. DHH has managed to keep steering his boat in the right direction, despite all the craze and hype around it.

The second reason is purely egocentric. I’ve just loved seeing acts_as_taggable being used as the example for the new plug-in architecture. ;-) Release notes quote:

For a while, we were struggling with what to do with cool extensions like acts_as_taggable. Clearly, it was good stuff and a high usable feature by many. (…)

This kind of thing really makes me miss those good days of Ruby hacking and being part of this great community.

And, speaking of that, I am actually looking for someone to replace me and take on development of the act_as_taggable library. I’ve been holding back on some nice suggestions and actual code contributions from users out there and I would really like to see this going forward. But I have no time to do it myself anymore.

Let me know if you have interest in being the new taggable guy, ok?

PS: Last awful truth of the day: did I mention I am managing a Java development team? Oh boy, I’ve got my soul sold to the devil. ;-)

Author: "--" Tags: "Software Development, Rails"

Date: Wednesday, 14 Sep 2005 05:59

There´s been already a couple of discussions on the Rails list about what would be the pros and cons on using GUIDs/UUIDs as primary keys ( instead of auto-increment integers) in ActiveRecord models. Let me sum it up:

### Pros

• Data Portability: it is much easier to do import/export/sync operations of multiple tables using GUIDs as PKs, specially if there are many relationships between the tables. Also, if your app (such as the one I am currently helping to build) uses distributed databases, this becomes a critical issue.
• DBMS Portability: you don´t depend on a specific database implementation of autoincrement keys or sequences, which can vary quite a lot for different DBMSes.
• Known ID upon object creation: You don´t need to wait until the object is persisted to know its ID. You get to know it as soon as the object is instantiated and that can make things a bit easier sometimes, specially when doing equality comparisons between saved and unsaved records.

### Cons

• Performance: if you’re using a Windows-style GUID, then obviously, a char(36) is slower to look up than a int(11), although I don´t think there is significant hit on most scenarions. (Care to prove me wrong on this?)
• Ugly URLs: Rails apps show object IDs on URLs, and let´s face it, GUIDs are ugly as hell.
• Chance of Duplicated GUID: if you use a decent or RFC 4122 compliant generation algorithm, then this is a non-issue.

Anyway, as I mentioned before, the project I am currently working on makes heavy use of distributed databases – not the typical Rails app scenario, I know – and as so, using GUIDs for PKs is critical for us.

I would really like to hear some war stories (good and bad) on usings GUIDs for primary keys in your databases, as well as sound opinions on the subject.

So, you want to try it out for yourself? How about this: drop this guid.rb file in your /lib folder and add require ‘guid’ to your environment.rb. After that, for the models you wish to use GUIDs as primary keys, define their id columns as char(36) and drop the guid macro inside your model like this:


class MyNiceModel < ActiveRecord::Base
guid

# other parts of your model here
...
end

Then, if you´re kind enough, share your experience of using this Guid thing with us, ok?

UPDATE: I´ve updated the guid.rb file to fix a very basic bug, so please download it again. I´ve also added a :column option, so you can specify a primary key column name different from ‘id’ as this:


class MyNiceModel < ActiveRecord::Base
guid :column => 'guid'

# other parts of your model here
...
end

NOTE: The Guid Extension for ActiveRecord provided here is experimental and should not be used in production/critical environments. Although the chance of GUID duplication is pratically zero, the generation algorithm is very simplistic and non-conformant with RFC 4122, so use it only for experiments.

Author: "--" Tags: "Rails"

Date: Tuesday, 13 Sep 2005 05:26

After a brief discussion with DHH on whether it would be better to try to make the “acts as taggable” mixin a patch or make it an independent library, we´ve came to the conclusion that the latter would be the wiser choice.

And so, I´ve asked Tom Copeland for a little room in his wonderful Ruby Open-Source Project Plaza, also known as RubyForge and now the “acts_as_taggable” macro has a brand new home at http://rubyforge.org/projects/taggable/.

Also, the most up-to-date online RDocs are available at http://taggable.rubyforge.org/.

Installing and updating the library is now as easy as gem install acts_as_taggable.

And after that, just add a require_gem ‘acts_as_taggable’ line to the ‘environment.rb’ file of your Rails app, and get taggable!

This new version also has some nifty additions for finding related tags and records that share a similar set of tags. Really useful for building those ‘Related’ and ‘See Also’ boxes.

Thanks again to Peter Cooper for all the tricky SQL part.

Author: "--" Tags: "Rails"

Date: Tuesday, 06 Sep 2005 16:10
There´s already a new version of the acts_as_taggable mixin available and look what it is capable of now:

# Gets the top 10 tags for all photos
Photo.tags_count :limit => 10 # => { 'beer' => 68, 'wine' => 37, 'vodka' => '22', ... }

# Gets the tags count that are greater than 30
Photo.tags_count :count => '> 30' # => { 'beer' => 68, 'wine' => 37 }


If you just got here by accident and want to see other examples, check out previous articles on the same subject:

And did you know it now includes complete RDoc documentation ?

I promise this is the last release of the week. ;-)

Author: "--" Tags: "Rails"

Date: Saturday, 03 Sep 2005 10:52

My last article about tagging on Rails attracted quite a lot of attention, much due to its appearance on the official RoR weblog, to my complete surprise and delight.

Nevertheless, a few heated discussions and criticisms appeared around it and, overall, it was very constructive, turning out to be a quick and effective way to gather quality feedback from smart people that are in need for this kind of functionality.

A lot of great suggestions and requests were made for improvements and now I am very excited to present the new features of the acts_as_taggable mixin. Here are some examples:


class Photo < ActiveRecord::Base
acts_as_taggable
end

photo = Photo.new

# standard tagging with a string
photo.tag 'brazil rio beach'

# tagging with an array
photo.tag ['south america', 'soccer']

# tagging with a different separator
photo.tag 'beautiful women, babes, hot chicks', :separator => ','

# tagging with a Proc separator
photo.tag '2001..2005', :separator => proc { |s| eval(s).to_a }

# suppose your tags_photos join table has attributes
# and you want to set them while you tag
photo.tag 'samba', :attributes => { :tagged_at => Time.now }

# Let´s do some tag searching now
# Photos with soccer OR rio
Photo.find_tagged_with :any => 'soccer rio'

# Photos with beach AND women (combo tags)
Photo.find_tagged_with :all => 'beach woman'

# Using a different separator
Photo.find_tagged_with :all => 'beach+woman', :separator => '+'


Ok, that´s all very nice, but it only works for global tagging with simple has_and_belongs_to_many join tables right? What if I want to use a full model for relating objects and tags, so that I can also use other mixins with it such as acts_as_audited, acts_as_lists, and also have access to ActiveRecord’s callbacks, timestamping and so on?

Good news, now you can! Show, don´t tell!

class Photo < ActiveRecord::Base
acts_as_taggable :join_class_name => 'TagPhoto'
end

# The join class specified above is created automagically,
# but we can still open it and extend it at will
class TagPhoto
acts_as_list :scope => :photo
belongs_to :user

after_save :do_some_stats
end

# I can do some nicer things now
photo = Photo.new

# If I used the acts_as_audited mixin,
# I don´t even need to do the attributes part
photo.tag 'rio sun hot', :attributes => { :user_id => current_user.id }

# Now, I wan't to find all photos in which the 1st or 2nd tag is 'rio'
# (remember that the acts_as_list works, so tags are sorted for each photo)
Photo.find_tagged_with :any => 'rio', :conditions => 'tags_photos.position = 1 OR tags_photos.position = 2'

# Or 'brazil' by some user
Photo.find_tagged_with :any => 'brazil', :conditions => 'tags_photos.user_id = 1'


I think it all turned out pretty nice, don´t you think?

A word of caution: I still haven´t properly documented all features and options of this new version, but I´ll do that in the next couple of days. Also, I don´t think the unit tests I wrote for it are covering all possibilities right now, so don´t expect a bug-free version as of this moment.

But if you´re brave enough to give it a try on your project, I´d be very happy hear from you and receive bug-reports.

A little warning for those who were using the first version: the previous version had a default behavior of clearing the tags collection on the #tag method. This has changed for this version. The default behavior now is to append the tags to the existing ones. You can still clear the existing tags using the ’:clear => true’ option. Also, the #tagged_by? method changed to #tagged_with?, so a little find & replace might be necessary.

To use it, just put it in your /lib folder, under your Rails app root and add a require ‘taggable’ to your config/environment.rb file.

You also have to have a ‘tags’ table with a ‘id’ as a primary key and a ‘name’ varchar column and a Tag model on your db schema/application. You can actually change the name of those if you´d like and specify them using the :collection, :join_table, :tag_class_name options, please see the RDoc comments included in the source. You also must have join tables, such as ‘tags_photos’ with foreign keys ‘photo_id’, ‘tags_id’, for example.

Happy tagging!

UPDATE: A bug that would prevent tagging unsaved objects has just been fixed, thanks to valuable help from technoweenie. Please download the latest version from the same location as before. The bug was caused by me improperly touching private parts of ActiveRecord ;-), so remember boys & girls, always talk to your peers thru the public interfaces.

UPDATE 2: There´s a brand new, more stable version available that features an improved API and also includes complete RDoc documentation.

Disclaimer: this mixin was extracted from the work I am currently doing together with a great team for the syncPEOPLE project, which is about to have its presence on the Web soon.

Special thanks to Peter Cooper for the tricky SQLs that allows tag searching and tag combos.

Author: "--" Tags: "Rails"

Date: Saturday, 27 Aug 2005 08:48

UPDATE: See the improved version in action here.

There’s been a lot of buzz about tagging lately (also known as folksonomy) in the websphere. It seems that every Web 2.0 website is doing it these days.

So, why be left behind?

There’s a lot of different data models to do tagging, but the most normalized and flexibe way is to use one unique table for holding all tags, and then using join tables between your taggable objects and the tags table for creating many-to-many relationships. Something like this:

photos <-> tags_photos <-> tags
message <-> tags_messages <-> tags


You may be thinking that it’s just too cumbersome to have such complex data structures for holding some lousy keywords? But before ranting about that, here’s some good info on the subject.

And if you’re doing Rails, you also may be thinking: ok, if I go with that, I’ll end up having a lot of has_and_belongs_to_many declarations in my taggable objects, as well as having to manage the many-to-many collections when adding tags to them, doing such things as checking for existing or duplicated tags, stripping spaces, and so on.

Wouldn’t it be nice if you could do all that just by doing this:

class Photo < ActiveRecord::Base
acts_as_taggable
end

elephant = Photo.find(4437)
elephant.tag 'zoo animals nature'

elephant.tagged_with?('urban') # => false
elephant.tags.size # => 3
elephant.tag_names # => [ 'zoo', 'animals', 'nature' ]


Ruby and ActiveRecord can make life so much easier, right? Just grab the acts_as_taggable mixin here.

(This is also available as a candidate patch)

Little disclaimer: this mixin was extracted from the work I am currently doing together with a great team for the syncPEOPLE project, which is about to have its presence on the Web soon.

Author: "--" Tags: "Rails"

Date: Friday, 26 Aug 2005 08:32

After a few bumps and tweaks (mainly related to migrating the old data), I managed to get Y.o.m.b.a.r. running on the latest trunk version of Typo 2.5.

The previous versions of this blog had some code customizations that are no longer needed, since the new version makes it possible to do the same stuff only by using the new administration features, specially the very cool sidebar components.

I took a good look on the code, and, boy, what a beautiful plug-in architecture they’ve got, really pushing Rails to its limits, APIs, components, it’s all in there.

Not too mention all the AJAX/drag-n-drop goodness of the new administration screens.

Congratulations to Tobi and all the Typo team. It must be funny for Tobi to see how Typo has evolved and got wide adoption, since he had so few ambitions with it at the beginning.

Yes, open-source magic.

Author: "--" Tags: "Rails"

Date: Thursday, 25 Aug 2005 03:39

I know a lot of people don’t like or strongly disagree on what Paul Graham writes, he may sound too elitist most of the time, but I have to confess I enjoy reading his essays very much, I even bought his Hackers & Painters book.

To me, one of the best articles he wrote was the (now classical) Great Hackers essay, which also is available in a very good audio version at IT Conversations.

One of the most controversial affirmations of this essay is when Paul says:

“But when you choose a language, you’re also choosing a community. The programmers you’ll be able to hire to work on a Java project won’t be as smart as the ones you could get to work on a project written in Python.”

I tend to agree with this affirmation, but maybe a little tweaking on the way you say it would have avoided much of the hatred around it. It is not that you can’t find great hackers working on mainstream technologies such as Java and .NET, I personally know a few geniuses that work on Java and .NET. But since it’s a much larger audience, the average quality of the crowd tends to go down, mainly because the entry barriers on those platforms are so low, with all the money involved, marketing, tools and industry-backed promotion.

Now, when you get to technologies that survive much more (or purely) due to its technical merits than promotion efforts, such as Python, Ruby or Smalltalk, you start to realize that the people that compose the communities around those platforms have something in common. I would dare to say that they are at a higher level of evolution in a technical sense, they surpassed certain stages of technical understanding to be able to realize that the lack of good tools or books or training are greatly compensated by the intrinsic qualities of the exquisite languages they now work with and that they can do a lot more with those languages using a simple text editor than using powerful 2-DVDs IDEs. But most importantly, they have more fun.

Going one step beyond technical qualities, I also find that people on these more restricted communities tend to be (on average, please) smarter than the ones in mainstream communities in other aspects too. They have a more refined sense of beauty and aesthetics (better taste), they are more pragmatic, they communicate better and are connected to wider realities and also have more sense of humor.

For instance, I am working in a Rails project right now where the whole team, including the client himself, is made of those kinds of people. I know it’s unusual to work with a client with deep technical knowledge, but I got lucky this time. He chose Rails over more established options such as ColdFusion (which he personally masters) and this alpha-geek attitude reflects on other areas of his personality as well, such as having flexible work hours, using web-based collaboration tools and even doing podcasts.

I was truly delighted to hear from him such motivating phrases as “If we build anything that might be useful to other people, let’s give it back to the community” or “Sure, I’d be glad if you blogged about the project” or simply “I completely trust your judgment on that”.

Yes, my client encourages me to blog and to do open-source development. I wonder what my odds would be of having the same thing if I was working on a .NET “enterprise” project for a big company. Don’t laugh please. :-)

Author: "--" Tags: "Ruby, Software Development, Rails"

Date: Wednesday, 24 Aug 2005 00:57

I’ve had my share of wrestling with Apache2 and FastCGI to get my Rails (version 0.13.1) apps running on my Windows XP box (not to mention my attempts with Lighttpd). Long hours trying to figure out configuration trickery for things that were not primarily designed to run on Bill’s OS.

But I have good news, I finally managed to get it working well enough these days. And to spare you, who are in the same boat, the same trouble, here are some useful tips.

First, let’s cover the basics:

Now, make sure you have mod_fastcgi.so in your Apache2\modules folder and that you have mysql.so and fcgi.so in your ruby\lib\ruby\site_ruby\1.8\i386-msvcrt folder.

Start a normal IRB session and type require ‘fcgi’ and require ‘mysql’. You should get ’=> true’ as a response from both.

Make sure you have these directives in your Apache2 httpd.conf file:


<IfModule mod_fastcgi.c>
</IfModule>

Now, a typical Virtual Host entry that should point to your Rais application would look like this:

<VirtualHost *:3000>
DocumentRoot c:/dev/myrailsapp/public
ErrorLog c:/dev/myrailsapp/log/server.log

<Directory c:/dev/myrailsapp/public/>
AllowOverride all
Allow from all
Order allow,deny
</Directory>
</VirtualHost>


Remember to add a ‘Listen 3000’ directive as well up in the httpd.conf file if you’re going to use that port.

Now, in your dispatch.fcgi file that resides in your Rails app public\ folder, make sure the shebang line is correct:

#!c:/ruby/bin/ruby


Finally, in your .htaccess file that resides in the same folder as the dispatch.fcgi file, change the rewrite rule that points to the ‘dispatch.cgi’ file and replace it with ‘dispatch.fcgi’.

So far, pretty standard stuff. Now, let’s get a little fancier. To make Apache2 more conservative when running on Windows, go back to the httpd.conf file and add these lines:

EnableSendfile Off
EnableMMAP Off
Win32DisableAcceptEx


Also, in the same file, you should dumb down the FastCGI powers (we are talking about a development machine, right?), and so, you need to limit the number of processes it is allowed to start, otherwise, it will just take too long when starting your app, and it will consume too much memory as well, and that might cause you trouble.

For that, you need to add the following directive to keep FastCGI on a minimum resource level usage:

FastCgiConfig -maxClassProcesses 1 -maxProcesses 1 -minProcesses 1 -processSlack 1


If you wish (or need), you might increase those numbers a little bit, but I don’t recommend going over 5 processes.

And then to the trickiest part. If you’re using native Ruby bindings such as fcgi.so or mysql.so or iconv.so or RMagick.so, those bindings usually rely on native DLLs that reside in folders such as Windows\System32 and others. And that is normally a source of problems and error messages such as ‘unitialized constant Mysql/Iconv/...’.

The problem is that FastCGI server processes doesn’t get any (yes, none, zero) of the environment variables of your system, being them either at machine-level or user-level. And that includes RAILS_ENV, RUBYOPT and more importantly the PATH variable. And without the PATH variable all native extensions that rely on DLLs outside the ruby\bin directory will fail. I discovered this after very long hours as you may imagine.

And don’t bother trying to use SetEnv or PassEnv directives. They won’t work at all with FastCGI.

The only solution is going back to the FastCgiConfig directive and adding all your environment variables using the ’-initial-env’ option. So, my complete FastCgiConfig directive now looks like this:

FastCgiConfig -maxClassProcesses 1 -maxProcesses 1 -minProcesses 1 -processSlack 1 \
-initial-env PATH="c:/ruby/bin;c:/windows/system32;c:/windows;C:/mysql/bin;C:/Progra~1/Common~1/GTK/2.0/bin"  \
-initial-env RUBYOPT=rubygems \
-initial-env MAGICK_CONFIGURE_PATH=c:/ruby/lib/ruby/gems/1.8/gems/RMagick-win32-1.7.0-mswin32/config


Important: always use ”/” on paths and always use the 8.3 short names when the path contain spaces.

With (all) this, I am able to use FastCGI very reliably and with excellent performance and also make all native bindings that I use (Iconv, Mysql, RMagick, and others) to work as well.

Originally, I tried all this to see if the UploadProgress helpers would work on Windows, since it requires FastCGI, but even then, it didn’t. I know I am supposed to allow more than 1 FastCGI process to make UploadProgress work and I did try that, but it didn’t work anyhow. So, if you manage to get it working, please, let me know how you did it! ;-)

An important tip to diagnose problems is that, if you get the infamous “Application Error – Rails application failed to start properly” message, there is usually something going wrong on in your ‘environment.rb’ file (or the files it is requiring). Rails won’t be able to present you any useful debugging information unless all of the ‘environment.rb’ gets executed right. So, it’s pretty hard to track the cause of problem in this situation, but normally, this is caused by some custom ‘require’ that you added to the file. The standard ‘environment.rb’ that gets generated from Rails is safe.

Remember to always restart Apache2 when you change the httpd.conf file (duh! But I did forget sometimes! ;-)).

I hope you can manage to get this combo working on your WinXP box with all this info. Let me know if you have any trouble, and I’ll try to help.

Author: "--" Tags: "Rails"

Date: Wednesday, 17 Aug 2005 22:46

I’ve just realized that the first version of the CHM help file did not have the methods within each class in the table of contents sorted by name, so I’ve just fixed that.

Author: "--" Tags: "Rails"

Date: Wednesday, 17 Aug 2005 02:11

Being a Rails developer on a Windows box can sometimes turn out to be a aggravating task. Spending a whole day trying to figure out why Apache2+FastCGI doesn’t work with the Upload Progress patch or wasting another day trying to compile lighttpd on cygwin, just to find out that it won’t work at all and other misfortunes gets you really thinking about switching to a nice Linux box, even if you still pay a lot of your bills doing .NET development.

Anyway, enough rant, today I decided to complete a mini-project that I had for a while to help ease the pain of fellow Windows Railers out there (myself included).

Thanks to a little inspiration from Martin Cohen, who just released a great Firefox extension, I’ve managed to put up a nice CHM Windows Help file containing full Rails 0.13.1 documentation.

The CHM File can be downloaded here and has all nice features of a Windows help file, such as a hierachical contents table, a index with all classes and methods of the framework and also full-text search capabilities.

I am trying to convince David to make it available directly on the Rails website on every official release from now on and I hope he agrees to it.

Let me know if you find out any quirks on the file or/and if you have any other suggestions.

Enjoy!

Author: "--" Tags: "Rails"

Date: Friday, 05 Aug 2005 08:44

If you are a smart person, you use some kind of version control system for all your beloved source code. If you’re even smarter, you use Subversion.

Even so, there’s something that always escapes being versioned in my Rails project, something which is a very crucial part of the Rails source tree: the MySQL database schema.

If you ever ran unit and functional tests on your Rails app by using the “rake” command, you’ll notice that each time you do it, a file called development_structure.sql gets created/updated on your db\ folder. That’s because “rake”, before running any tests, recreates the test database from the latest development database structure.

That has the side-benefit of enabling the database schema for versioning on your next Subversion commit.

However, if you still haven’t absorbed this test-driven development thing, where you write the tests before the actual code, many times you won’t run the “rake” command and your latest db changes won’t get properly versioned.

Rake to the rescue again and some command-line magic to solve this dillemma! Thankfully, generating the development_structure.sql file is a isolated Rake task and if you only want to do that, simply type “rake db_structure_dump” on your command-line (Type “rake—tasks” to see the other useful rake tasks you have available).

Combine that with a “svn commit” command in a batch file (or shell script) and you should be able to see your database schema versioned at every commit action.

commit.bat (put it in your Rails project root)
rake db_structure_dump && svn commit


You must have have your SVN_EDITOR environment variable properly set in order for this to work.

I am running a Windows box here, so I tend to use the excellent TortoiseSVN GUI client for all my Subversion operations. Luckily, TortoiseSVN can be automated as well:

commit.bat (put it in your Rails project root)
rake db_structure_dump && tortoiseproc /notempfile /command:commit /path:"c:\path\to\your\project" 

You must have “tortoiseproc”, located at Program Files\TortoiseSVN\bin, in your PATH or use the full path for that.

Now, just remeber to run the batch file (or shell script) for your commits and you and your database should be safe.

Author: "--" Tags: "Software Development, Rails"

Date: Tuesday, 26 Jul 2005 03:02

If you’re building Web 2.0 applications, you don’t want to polute your HTML code with formatting and layout stuff right? A much better place for that resides in the cascading styling sheets.

At first, you start with a global CSS file, included in every page thru the ‘link’ tag. But as your website grows in complexity, so does your CSS file and things start to get real messy. Suddenly, you can’t find anything in that gigantic CSS spaghetti.

So, you start refactoring your CSS file into smaller, modular files. And to keep things simple and neat, you adopt a naming convention for the CSS files: [controller_name].css for all actions in a controller and [controller_name]_[action_name].css for a specific action in a controller.

Great, but then you realize that you’ll have to add specific “link rel” in every RHTML template file to actually make it work.

Well, since I am coding in Rails, I want to see some magic. Wouldn’t it be nice if I could just drop a <%= stylesheet_auto_link_tags %> in the HEAD section of my layout file and then, Rails would include the right CSS files for me? And please, only if they actually exists, right?

Here what goes into my application_helper.rb file to make it happen:

stylesheets_path = "#{RAILS_ROOT}/public/stylesheets/"
candidates = [ "#{controller.controller_name}",
"#{controller.controller_name}_#{controller.action_name}" ]

candidates.inject("") do |buf, css|
buf
end
end

This little snippet is also available at Code Snippets (what a great site!), thanks to Duane Johnson

Now, do you think I should try to get this into Rails/ActionPack for good?

UPDATE: After talking with some people on the #rubyonrails IRC channel who found this snippet very useful, I’ve decided to submit it as a patch – it’s an improved version, with documentation and tests. I hope it makes into the next Rails version.

Author: "--" Tags: "Rails"

Date: Sunday, 24 Jul 2005 22:21

I guess we are close enough to launch day, so I can emerge from stealth mode and start talking a little bit about the project I’ve been putting together with a friend.

My friend, who happens to be one of the best designers I know, has among his peers here at Brazil a whole lot of other designers, nothing really exciting so far. But, have you thought of how many designers and artists in his field are skilled in designing great t-shirts and how many would very much like to do it if it wasn’t for all the trouble they must go thru to get a real self-designed t-shirt in their hands?

I mean, t-shirt designers and artists love to design the t-shirt art and that’s it. They don’t want to (at least, most of them) deal with actual production details, like choosing the right fabric, or dealing with suppliers, or charging clients and setting up credit card payment systems, and so on and so forth. Wouldn’t it be great for them if they could just upload their Photoshop file somewhere and a few days later receive an actual high quality t-shirt with that same art they’ve sent? And better yet, be able to actually make money from it?

FABRICKA, which in Portuguese language means ‘factory’ (with a slightly different spelling), is a community-driven website where t-shirt designers and consumers share a commonplace.

If you’re a t-shirt designer, you’ll be able to upload your t-shirt art to us, order the production, and we’ll take care of the rest. Even setting up your own virtual t-shirt store at ‘yourusername.fabricka.com’ will be a click away. And once your t-shirt start selling, you’ll get paid for it! And who knows, you might even get famous too!

If you’re just like me and love wearing t-shirts and would like have a vast variety of cool t-shirts and artists to choose from, then you’ll also like to participate in the FABRICKA. Besides browsing and buying t-shirts, you’ll have your own weblog and blog all about it, talk directly to the designers and artists, comment their t-shirt designs, upload photos of you and your friends wearing Fabricka’s t-shirts, indicate your favorite t-shirts and designers and a whole lot more!

So, if you’re a brazilian t-shirt fan, head on to the temporary website at http://www.fabricka.com (or http://www.fabricka.com.br) and drop your e-mail there, we’ll let you know as soon as we go live for real.

After all, the t-shirts you wear are all about your attitude towards life, right?

Author: "--"

Date: Saturday, 23 Jul 2005 01:04

I know, I know… These days, I should be using Unicode strings everywhere in my applications.

Well, the fact is that I don’t trust the Unicode support that Ruby provides yet (stable 1.8.2), as demonstrated here by _why. The same goes for MySQL and, to close the deal, my favorite IDE doesn’t handle UTF-8 files.

Besides that, I am building a web application that’s very unlikely to need to show characters others than the ones supported by the Latin1 charset.

So, I stick with the ISO-8859-1 charset and the old plain 8-bit ASCII encoding.

But then, when I post a form with accentuated characters in my app using AJAX, bam! I find out that XmlHttpRequest always use UTF-8 encoding for sending data down the HTTP channel, always.

No problem, iconv to the rescue, and since it’s a Rails app, I add the following ‘before_filter’ to my controllers/application.rb file:


require 'iconv'
class ApplicationController < ActionController::Base
before_filter :convert_xhr

ICONV = Iconv.new('ISO-8859-1', 'UTF-8')

def convert_xhr
convert_hash(params) if request.xhr?
end

def convert_hash(hash)
for k, v in hash
case v
when String: hash[k] = ICONV.iconv(v)
when Array: hash[k] = v.collect { |v| ICONV.iconv(v) }
when Hash: convert_hash(v)
end
end
end




The above code converts all strings in the ‘params’ hash from UTF-8 to ISO-8859-1 (only when things come down thru AJAX). And that saves my day, for now.

Author: "--" Tags: "Ruby, Rails"

Date: Monday, 11 Jul 2005 23:17

I can’t thank Curt Hibbs enough for bringing an excellent port of Ruby to the Windows platform, all wrapped up in a nice installer package.

Besides that, the guy wrote the most popular tutorials on Rails published on the O’Reilly ONLamp site and managed to get it all slashdotted as well.

He even finds time to dedicate to other nice stuff such as FreeRIDE (Ruby IDE), WxRuby and the Ruby for Apache project, which includes binaries for the FastCGI and ModRuby bindings on the Windows platform. CORRECTION: I mixed things up here. Kent Sibilev is the responsible for the Ruby for Apache project, as pointed by Curt himself in the comments. Curt Hibbs is working on the EasyRails project (formerly known as the One-Click Ruby Server).

Recently, Ruby for Apache included the native MySQL bindings for Windows as well, which speeds up things considerably when using MySQL as the backend database in a typical Rails application.

For instance, I’ve been tinkering with RForum (a nice forum application built on Rails) lately, trying to bring it up to the latest Rails version (0.13.1), so I’ve been running the unit tests included in it. If I use the pure MySql Ruby driver, the tests take 598 seconds in my machine. By using the native binary MySql driver, the same tests take 58.7 seconds to complete. Yes, more than 10x faster.

The only problem is that since I’ve started using the MySql native bindings that came in the Ruby for Apache package, I’ve been getting frequent segmentation faults, the nastiest bug you can get in Ruby. I am pretty sure that the segmentation faults were being caused by some weird combination of my Ruby (1.8.2 (2004-12-25) [i386-mswin32]) and MySQL (14.7 Distrib 4.1.12a, for Win32 (ia32)) versions.

So, I headed to the original MySQL/Ruby page and downloaded Tomita Masahiro’s sources. I’ve already experimented compiling native Ruby extensions before when I’ve spent over 6 hours trying to compile the native bindings of the RJNI Ruby-Java bridge. I managed to do it then, so I was willing to try it again with the MySQL bindings.

Compiling Ruby native extensions on a Windows box is not for the weak of heart, but I hoped that my previous, gruelling experience with RJNI would pay off now. And it did! In about half hour I managed to have a compiled mysql.so.

I ran the RForum tests again, 58 seconds later and no segmentation faults this time, I’m happy.

So, if you are experiencing the same symptoms, here is the medicine: MySql.zip. Just drop the .so file into your \ruby\lib\ruby\site_ruby\1.8\i386-msvcrt folder and you should get instant relief.

Again, here’s my configuration:

• Ruby 1.8.2 (2004-12-25) [i386-mswin32]
• MySQL 4.1.12a
• Compiled with Visual Studio .NET 2003

UPDATE: As it happens, my first tests were executed with Rails version 0.13.0, which contained a serious performance bug related to the MySQL pure Ruby driver. That was solved today with version 0.13.1 and after running the tests again with the pure Ruby driver, it took only 80 seconds (you still get 40-50% faster performance with the native drivers). Thanks to Tobi for pointing that out on the Rails list.

Author: "--" Tags: "Ruby, Rails"

Date: Tuesday, 05 Jul 2005 16:56

These days I am back doing some ASP.NET development for my company, working on our flagship e-learning product, mostly fixing bugs and adding a few small features, which is also known as maintenance – a (mostly) painful, but necessary, part of our job.

And suddenly I discover how much extra effort there is to do extremely simple things on my ASP.NET software than there would be if it was coded using Rails. And this is not just a simple matter of an ASP.NET vs Rails comparison, although Rails and Ruby helps boosting productivity in a lot of aspects. Even by sticking to ASP.NET, I felt I could be at least 3 times more productive with it if I only did things right early on. Let me explain.

Among my daily blog reading there is the Larkware News by Mike Gunderloy, who wrote the excellent Coder to Developer. His column, The Daily Grind helps me get updated on a lot of software development subjects, mostly related to .NET. In one of his recent posts, he mentioned a free (but not so much) RAD framework for .NET called IdeaBlade-Lite that integrated an ORM and UI databinding in an MVC architecture. Hmmm… It felt very familiar, so I decided to check it out.

IdeaBlade is commercial software, the Lite version allows you to use their product for building only client/server Windows applications and that’s good enough for experimenting with their product. One of their marketing statements says that you can reduce your coding by 70% if you use their product. This would be just another over-hyped marketing statement that I would gladly ignore if I hadn’t had the experience to build web apps with Rails and then go back to do some traditional ASP.NET coding.

I realized that most of the coding (yes, 70% or maybe even more) that goes in data-driven applications is of 2 kinds: bringing or sending data from the database to your objects and capturing or presenting data from the user screen to your objects. That’s purely mechanical, boring code that a chimpanzee could write and that’s exactly what a good ORM and UI binding framework, such as Rails (and maybe IdeaBlade) would gladly do for you.

The main problem here is that until you have the actual experience of working with a good framework like Rails to ease your pain, you don’t feel the pain at all! Or maybe you do feel it, but you just don’t know where it hurts. And to make matters worse, there are very few people that do things differently from you, so you just convince yourself that’s just part of the work.

Traditional ASP.NET development means coding everything on your own, following some of the .NET industry “best practices” promoted mostly by Microsoft – their blueprint examples all do things ‘traditionally’, and then you assume to be the best way to do it. That includes writing stored procedures for every tiny database mangling you need to do and using Datasets and their brothers and sisters for carrying data over the layers, and so on. Object-relational mappers? Who needs them, right? WRONG!

Why is Rails so much more productive than classic ASP.NET development? I acknowledge that mainly to 3 factors:

• The ActiveRecord component. This excellent ORM layer combines the simplicity of the active record enterprise pattern with virtually unlimited power. Substantial productivity gains comes from the sole fact that you don’t have to write 99% of application SQL code anymore. Nice, huh?
• Rails full stack integration and smart defaults. Rails doesn’t offer you (at least, DHH don’t market it enough) UI binding, but it’s there, it sure is. If you give your UI controls the right names, accordingly to your object attributes, you can transfer data from your objects to the screen (and vice-versa) with only one line of code. Neat, huh?
• The Ruby language. Ruby is such a dynamic and powerful programming language that you can bend it to do pretty much everything you need without breaking it. And that’s something that C# isn’t meant to do. ActiveRecord wouldn’t be possible if it wasn’t for Ruby.

So you see, 2 of these factors are related to ORM and UI binding, and that’s something you CAN have (although not in the same neat Ruby way) in .NET development. Oops, that was an understatement, so let me re-state that: that’s something you MUST have.

Do yourself a huge favor and stop writing chimp code now. Get a nice framework to do that for you on your next ASP.NET project.

UPDATE: There is a genuine attempt in the .NET open-source community to get closer to the Ruby on Rails way of building web apps that goes by the name of MonoRail (cool name!), which is part of the Castle Project and led by fellow brazilian developer Hamilton Verissimo. I’ll be posting about MonoRail very shortly, stay tuned.

Author: "--" Tags: "Ruby on Rails vs ASP.NET, Software Devel..."

Date: Saturday, 25 Jun 2005 18:14

I’ve just posted this in reply to Stephen Kellet’s question about ‘Rails vs. ASP.NET’ in the comp.lang.ruby newsgroup, so I think it might be good to post it here too for future reference:

Hi Stephen,

(...)

I think both ASP.NET and Ruby on Rails approach different ways for building web apps, but both manage to do it in a very high quality manner.

In the end, it’s much more about developer’s taste and less about technical aspects.

For instance, if you’re leaning more towards statically-typed languages and are used to have a compiler and a top-notch IDE (VS.NET) to help you out, then by all means go with ASP.NET.

On the other hand, if you prefer simpler tools (more text-based), dynamic languages, and running your app in a interpreted, more agile environment, RoR might be a good fit.

On the technical side, ASP.NET as we all know has some portability issues, so, despite of Mono, your best bet on a production environment would be on a Windows web server and a SQL Server database. Remember the high costs of that.

RoR is based on a completely free, open-source stack (Ruby, Apache, Lighttpd, MySQL, Postgre, etc) and runs well on pretty much any OS platform out there, be it Linux, FreeBSD, Windows, MacOS, Solaris, etc.

If your going with RoR, remember to allocate some quality time for studying the language and the framework and getting used to new tools and environments and learning how things are done in a open-source community. It takes some time to get up to full speed, but at the same time, can be a revealing and rewarding experience.

Of course, these days, I’d recommend RoR, but remember that that’s what best fits me, and it might be different for you. Anyway, you will be in good hands if you go with ASP.NET as well.

(...)

Author: "--" Tags: "Ruby on Rails vs ASP.NET"

Date: Thursday, 23 Jun 2005 18:32

HyperDE (Hypermedia Development Environment) is the pretentious name for my masters degree project, which was concluded successfully in the last March, 30th. Shortly, HyperDE is a combination of a web-based development environment and a MVC framework (based on Rails) to develop prototype semantic web applications modeled with the OOHDM method. It uses Sesame (a RDF database) as the back-end data storage, which forced me to re-implement most of ActiveRecord into what we now call ‘SemanticRecord’.

It was my first experience with Ruby, Rails and the open-source world (before that, as you may know it, I was mostly a Microsoft .NET developer). And let me say, it was a life-changing experience. Back then I used to browse the net with IE6 and Outlook was my email client. Thunderbird and Firefox rule my desktop these days.

My guiding professor, Daniel Schwabe, (who invented OOHDM) got so excited with HyperDE that started literally touring with it around international conferences and events and managed to raise a good level of interest among the academic community.

He also adopted HyperDE as the standard practical environment for teaching his OOHDM class in our university. And since last week, I’ve been teaching a series of 3 classes on how to use HyperDE to his students. And I’ve been getting all kind of reactions, from utterly terrorized faces to delighted excitement.

That’s why we decided to deliver HyperDE to the rest of the world (oh boy), and turned the project open-source. We are currently campaigning to gather developers and users to help improve the system. So far, we got 2 people already developing some nice extensions and also a few users that are trying to crank up some kind of semantic web application with it.

So, if you got interested (are you really?!) in helping us out and would like to work on semantic web technologies or do some volunteer programming on Ruby on Rails, please drop us a note. WARNING: This is a pre-alpha system with pratically no documentation, but we are already working to improve on that. A pre-requisite for helping would be to have good knowledge of the OOHDM method somehow.

Oh, and did I mention HyperDE was submitted for funding to Google’s Summer of Code ? Our fingers are crossed!

Author: "--"

» You can also retrieve older items : Read