Including gems with new rubygems

Have You seen something like this:


NameError (undefined local variable or method `acts_as_taggable' for Route:Class):

after You have upgraded to rubygems-0.9.2? Well I saw and did a little investigation. The results:

With new rubygems require_gem is replaced with gem command. One of the differences is that with gem autorequire feature is no longer enabled. In other words gem prepares LOAD_PATH with directory with gems code, but does not include gems code automagically. So with gem command including acts_as_taggable should look like this:

gem 'acts_as_taggable'
require 'taggable'

As You can see we need to specify directly file with gem code (but we don’t have know what path is needed). The question is what we need to include. Well, this information we can get from gem itself, using shell gem command (following block is shell CLI not Ruby code):

[viciu@bsd ~]$ gem spec acts_as_taggable| grep autoreq                      
autorequire: taggable

This way we know what we have to include to run gem.

Google Maps API setImage or no more events redefinition

Before Google Maps API in version 2.75 changing icon for GMarker was not so easy. Why? Deleting old marker and creating new one is quite straightforward. But deleting marker means delete events associated with this particular marker. And recreating them for new one makes things much more complicated. Especially when events are added during application life time, You have to watch which were added and what listeners are responsible for handling them. Or I should write You had, since setImage() does just that – replaces image associated with marker. Deleting is no more required.

As You may expect I’m preparing an update to RNS. With this development round I’m also bringing application to compatibility with current stable Rails (from 1.1.6 to 1.2.3). And I have discovered change with script.aculo.us behavior, in Ajax.Updater in parameters option. In Rails 1.1.6 it can be sign symbol used several times in string (like swlat=333.3;swlng=444.4) in 1.2.3 string is truncated on second sign symbol. I have rewritten my code to encode string in other format in only one parameter and Rails application unpacks it before processing. Other solution could be to play with postBody Ajax.Updater property. This allow to set whole body of request, so we can set many variables.

Now go back to coding, some few more features wait to be implemented!

RuPy 2007 or why Rails still amazes me

Last weekend I was speaking on RuPy conference. I had time to take part only on Sunday, so I missed first day, and what is probably key event of every conference, evening meeting in bar. Well, maybe next year.

For RuPy I had to refresh my speaker skills (last my speak on conference was something like in 2002). Well, I hope I did useful presentation. For me was very useful ;-) since I have learned a few new things. First, I was talking about EJS templates (minus mor plugin by Dan Webb). EJS provide efficient way to generate JavaScript code from Rails view level. Well day before my presentation I found simpler solution, than EJS to JS generation. In action set headers["Content-type"] = "text/javascript" and in RHTML template write JavaScript code with well known RHTML symbols <%= and <%. I did not found this though last few months – Rails still makes me nice surprises ;)

I was struggling with send_data a lot to generate code for RNS and solution was so simple. But, anyway, as I said in Poznan – I will still use EJS templating system. When I need to generate a lot of JS code I see two reasons to use EJS. First, that having another extension (.ejs) to separate JS views is right way, and secondly (and most important) EJS provides js helper, which escapes Ruby output to JavaScript safe string (like h helper for HTML in RHTML templates).

Second thing I learned from my presentation is that I can bear well with public coding… Result? Probably in May I will prepare session with live coding to introduce Rails and Ruby to people who did not drink Rails Kool-Aid yet. I will disclose more details ASAP I will know more – when, where and what exactly.

And talking about my presentation – You can download it: slides in PDF (with some remarks) and code from live session.

MUD, AJAX and real world

Before I have left for Internet free zone (Easter!) I have found this site http://www.ajaxmud.com/. It is somehow realization of my idea from almost year ago. This MUD sucks ;-) even if subtitle says it does not, but hey! this early development stage. But I don’t think ajaxmud.com will move out of this stage, since from its web page I can tell it was one-time effort.

Leaving for Internet free zone I took my laptop with me, since I wanted to play a little more with Ruby on Rails and AJAX. I have to improve those skills. So, I thought why not to try to bring to life AJAX MUD idea, but the Rails way.

I have spent something like 4 hours during holidays on this project and got basic skeleton running. Locations, exits, command interpreter. Well then I got to this conclusion: web based MUD have to suck. AJAX interface won’t help much. Why, You ask?

MUD games are oldschool and moving its interface to web does not feel right. When in browser window You don’t expect terminal like interface – You want graphics, rich text, etc. With my dumb application I could feel this very clear. Adding features and interface candies would help a little, but this does not change basic fact – MUD does not fit very well in WWW world – mentally not technically.

Probably some kind of web based game with MUD-like elements will succeed, but not MUD in its pure form ;-)

Toggling GMarker on and off

Finally, with new release (v2.77) Google Maps API provides interface to toggle on and off markers on map. I will test it soon, since right now with Run-N-Share I have some problems with markers highlighting. Now to highlight marker I have destroy old one and create new one. In FireFox it causes some delay, and it is especially visible with onmouseover/out.

With this feature (marker.hide()/marker.show()) it will be possible to do more smoothly. Just prepare two sets of markers to display (normal and highlighted) and toggle particular marker when mouse pointer hover over search results – should be enough.