Hi, this blog is no longer maintained, my new blog is here

Ruby On Rails and a Conning Israeli entrepreneur

|OFF| If languages were religions

Ruby would be Neo-Paganism - A mixture of different languages and ideas that was beaten together into something that might be identified as a language. Its adherents are growing fast, and although most people look at them suspiciously, they are mostly well-meaning people with no intention of harming anyone.

http://www.aegisub.net/2008/12/if-programming-languages-were-religions.html

Finally on Mephisto

It wasn't easy, but i made it.
finally the move is complete and 'Elad on Rails' is running safe and sound on my local machine (domain move is expected soon, after Christmas maybe).
The move was not as simple as i expected, Blogger does not offer an out-of-the-box solution for exporting your blog posts/comments, but as i mentioned in the move planning post, i found a way to do that using the Blogger draft engine. This was a hugh disappointment, the xml that was produced by the export option was terrible and made me realize that there is no simple way to get out of blogger (and Mephisto didn't help as well, no BloggerConverter implemented...rrrr).
So, i decided to do the easiest and simplest thing as possible, installed a local version of WordPress, imported Blogger (yes, WordPress has a blogger import tool) and from WordPress to Mephisto it went like a breeze (Using the Mephito WordPressConverted).
They only thing that went wrong is that i had to lose the Hebrew tags from blogger, apperantly Mephisto doesn't like Hebrew.
That's it.

Moo.rd: lightweight Mootools extestion

Mootools is awesome, but it still lacks some of the features that JQuery has when dealing with effects and some other not-so-important stuff.
Moo.rd is an excellent extension which implements some more features back to mootools. features such as some extra effects (finally, a mootools shake effect!), windows, sliders and more.
recommended, get it here.

Javascript Frameworks: i am changing my mind

well, originally i chose JQuery, which seems too-awesome-to-ignore at the time, but a recent project made me decide to try Mootools once again, well, it's amazing.
MochaUI is an excellent UI library in Mootools, the simplicity is overwhelming and on top of it all the dynamic pseudo selectors as lately mentioned in David Walsh's blog... amazing.


/* grab "checked" elements */
Selectors.Pseudo.checked = function() {
return ('input' == this.get('tag') && ('radio' == this.get('type') || 'checkbox' == this.get('type')) && this.checked);
};

/* grab "selected" option elements */
Selectors.Pseudo.selected = function() {
return ('option' == this.get('tag') && this.selected);
};

/* grab random elements */
/* credit: http://blog.kassens.net/custom-pseudo-selectors */
Selectors.Pseudo.random = function(probability, local) {
return Math.random() < (probability || .5).toFloat();
};

/* grab elements with no value */
Selectors.Pseudo.noValue = function() {
return '' === this.value;
}

/* grab elements with a specific empty attribute */
Selectors.Pseudo.emptyAttribute = function(att) {
return this.get(att) == '';
}


i think i might have some second thoughts about JQuery..

Observers, Associations and Callbacks

In my latest project, i need to notify a user via email about a certain kind of instance being created, so far normal.
This instance is created with a several of associated instances, let's say i am creating an article instance with linked categories using the virtual attribute technique (RailsCasts #16).
I created an observer for the article class to send an email with the article and categories after a successful creation of an article instance, therefore i immediately assumed that the correct callback is after_create. well, it's not.

when i used after_create, the email arrived with an empty list of categories, almost like they weren't saved, but a short trip to the console showed that the categories were created and that they are associated to the article as i wanted.

The problem resides in the order rails does this nested object creation, first the initial object is being created (the artical) and only than the association are created (after i used #build, watch the screen cast!), which causes the email to be triggered one step earlier than i wanted.

after finding this article i changed the observer's callback to after_save which apperantly is being triggers after the associations are saved as well.

i spent a lot of time on it, hope this helps.

Ajaxian: YQL - converting the web to JSON with mock SQL

Yahoo! now enables us to query a web page just like we would in sql. give it a try at YQL - converting the web to JSON with mock SQL

Google's Native Client plugin

Google has released a new experimental browser plugin that allows web applications to securely run native code on the underlying platform. The plugin, which is called Native Client, is distributed under the open source BSD license and is designed to work with all major platforms and browsers.

Native Client provides a sandboxed web-embeddable runtime environment for portable x86 binaries. It also provides a bridge to facilitate communication between JavaScript and Native Client executables. This makes it possible for complex web applications to seamlessly leverage native code for processor-intensive computations.

i don't know about you all, but it scares me :)
Source

Using ruby on rails with Oracle Legacy.

Great slide on SlideShare.
introduces the ruby-plsql gem, which makes it easier to preform database functions and stored procedures from ruby/rails applications (and supports bind variables).
i personally wrote a module of my own to handle this need (which supports bind variables as well).
Check out the slide and pay attention to the oracle_enhanced_adapter now available.
The slide is over here at SlideShare.

Moving to Mephisto (hopefully)

i have had it with this blogger account, you can say a lot of good things about this blog platform, but it is still a shared blog platform and it's not very professional to store you crown jewel on a blog platform which is written in Python :).
So i decided, i am moving to Mephisto. Mephisto is a Ruby on Rails blog platform and a self proclaimed "Best blog platform ever". well, i don't really know if that is true or not, but after checking it out locally i decided to use Mephisto for my permanent new blog.
The only problem i have right now, is how to transfer my Blogger posts/comments into my brand new Mephisto database. Mephisto is equipped with a "converstion" tools from Wordpress and Movable-type and as far as i know, nothing for blogger.
the blogger draft service (experimental blogger interface) enables you to download your entire post and comment history as XML so i might try to simply parse it into the DB (Or write a Converter).
Anyway, i'll be kinda busy doing it in the near future, so probably no posts in the near future.

Free idea: pastie like installation instructions

Sometimes when I google for installation instructions (for a gem, plugin whatever) I come across with blog posts containing old and out of dated installation instructions (old versions for example).
Why not create a pastie like engine for people to create and search for the most updated instructions? This engine should be smart enough to get a URL/svn/git/FTP address and fetch the latest file for each entry.
Of douse, a widget for bloggers should be mandatory.
I don't have the time to do it alone, if anyone feels like picking up this glove with me, just tell me.

Periodical AJAX requests and Session Expiry

My current applicaiton requires a session expiry feature, so fat, pretty ordinary, i decided to use the limited sessions plugin, as i always do.
The problem came up when i found out, that sessions aren't being released after the desired time had passed.
What was the problem?

first we will need to understand how rails uses sessions, basically it's something like that

  • session is retrieved from whereever it is. (ActiveRecordStore,CookieStore...)
  • Controller#Action is being preformed
  • Session is saved
now, where is the problem? when using periodical ajax calls, the session is being updated as it is after every action, so the 'updated_at' field, (required by the plugin) is updated, what causes the expiry interval (assuming it's bigger than the periodical AJAX calls's interval) to never be met. so no session expiry.

Solution

In my application.rb, i have a before_filter which updated the session with user_id in order to relate the session to the user, i migrated another field into the session table so i can keep my own track over changes, named it 'last_updated' like that

class AddCustomUpdateDateToSessions < ActiveRecord::Migration
  def self.up
    add_column :sessions, :last_updated, :datetime
  end

  def self.down
    remove_column :sessions, :last_updated
  end
end
and changed the application.rb method to update the new field, instead of the 'updated_at' field, and prevented my AJAX requests to update to the session, no need.
before_filter :update_session
  def update_session
    unless request.xhr?
      if logged_in?
        if session.model.user_id.nil?
          session.model.update_attribute(:user_id, current_user.id)
        end
        session.model.update_attribute(:last_updated, DateTime.now)
      end
    end 
  end
(yeah, i know it can be done better.) i also needed to change all the 'updated_at' references to 'last_updated' field inside the plugin's limited_sessions.rb, in order to completely take control over the session update flag. now it's working and my ajax calls do not cause the expiry interval to expire.

attachment_fu and minimagick resize bug

In one of my latest projects i was using the attachement_fu plugin to handle image uploads.
The attachement_fu plugin enables the option to select an image processor engine between ImageScience, Rmagick add MiniMagick:

  1. Rmagick
    Kinda bulky, leaking but fully functional
  2. MiniMagick
    Simple version of Rmagick, simple and small.
  3. ImageSceince
    Small, nice, and quick.
i decided to use MiniMagick as my processor, i installed the gem:

sudo gem install mini_magick


and added a specific :processor option to my Logo model.

has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabytes,
:resize_to => 'x100',
:processor => :mini_magick


but when i was uploading an image, i was was expecting it to be resized based on the options i specified in the model. imagine how surprised i was when i found out that the image is not being resized.

checking the log found the following error:

Exception working with image: ImageMagick command (identify "/var/folders/Bv/Bvbna8-OH548ZWju8naF4U+++TI/-Tmp-/minimagick11451-0") failed: Error Given 32512


Googling it didn't help me much (except from finding other people with the same problem), so i decided to switch to ImageScience instead (RMagick is out of the question of course).

sudo gem install image_science


this will include all most all dependencies, the freeImage dependency is also needed.
us mac/darwin users can simply use port:

sudo port selfupdate
sudo port install freeimage


now change the processor in the model

has_attachment :content_type => :image,
:storage => :file_system,
:max_size => 2.megabytes,
:resize_to => 'x100',
:processor => :image_science


and now it's working. yeah!.

Skype Weblinks - Call a skype user or send an IM message in a html page

When the user has installed Skype, one can open Skype directly from a webpage. The protocol is skype:skypename - and some other optional flags.

The example will use my skype username, but i am sure you will be able to get the hang of it.

Call a skype user
The optional flag is call - to force Skype to call somebody. It can also be left out - but if the user changed the default behavior to e.g. chat - Skype will open an IM session instead. So - go the save way and use the call - flag.

Example: call a Skype user


<a href="skype:eladmeidar?call">Call</a>


Send an Skype IM message to a Skype user

The optional flag is chat. See the example below to see the usage in a html page.
Example: send a chat message to a Skype user


<a href="skype:eladmeidar?chat">Chat</a>

Send a voicemail to a Skype user
The optional flag is voicemail - as you might have guessed.
Example: send a voicemail to Skype user


<a href="skype:eladmeidar?voicemail">Voice mail</a>


Create a Skype conference call with multiple users
This is as easy as the examples above - just more usernames before the "?" and call as flag.
Example: create a Skype conference call


<a href="skype:eladmeidar;otherfriend123?call">call 2 friends</a>


Create a conference chat with multiple users
Same as conference call - with chat as flag.
Example: open a conference chat with multiple users - in html


<a href="skype:eladmeidar;otherfriend123?chat">Chat with 2 friends </a>


i am now working on a rails plugin to implement this automated use for Rails applications

Rails 2.2: Getting Started link list

General Documentation and Guides

From railsinside.com

Rails 2.2 Release Notes - A very solid set of release notes for 2.2 with basic coverage of the new features (with short code examples and links) as well as a list of deprecated features. They were compiled by Ruby / Rails Inside's very own Mike Gunderloy!

Upgrading RubyGems to 1.3.x - Depending on your setup, Rails 2.2 may demand that you upgrade to RubyGems 1.3.x. This is not as easy as it might usually be, however. Mike Gunderloy gives some tips in case you get stuck.

Rails Security Guide - Steer clear of security issues in your Rails 2.2 applications by reading the Ruby on Rails Security Guide. Who said Rails has poor documentation? This is incredible!

Rails 2.2 Screencast - Gregg Pollack and Jason Seifer of Rails Envy put together a very solid Rails 2.2 screencast. It costs $9, but it covers a lot of ground over 44 minutes - learn about etags, connection pooling, new enumerable methods, new test helpers, and more.

Rails 2.2 - What's New - In association with EnvyCasts, Carlos Brando and Carl Youngblood present Rails 2.2 - What's New, a 118 page PDF covering all of the changes and additions to Rails 2.2. It's available in a package deal with the screencast (above) too.

InfoQ's Glance - InfoQ's Mirko Stocker takes a quick glance at some of Rails 2.2's new features.

New Features

Thread Safety - Rails 2.2 is now "thread safe." In October, Pratik Naik wrote a summary of why this is a big deal as well as some gotchas (basically, don't use class variables, use mutexes, etc.) Charles Nutter has also written What Thread-safe Rails Means which answers several pertinent questions.

Internationalization - The Rails Internationalization effort has its own homepage at http://rails-i18n.org/ which features lots of links to how-tos, tips, documentation, and demos. They also have a Google group / mailing list where you can get help, make suggestions, etc.

Basic Language Internationalization - It's a little old, but Simple Localization in Rails 2.2 gives a very quick, code-driven example of how basic internationalization works in Rails 2.2 (some of the set up is easier now, but it mostly applies).

Localization / Internationalization Demo App - Clemens Kofler has put together a demo app that shows off some of Rails 2.2's internationalization and localization features. If being knee deep in code is the best way for you to learn, jump in!

Layouts for ActionMailer - As of Rails 2.2, you can now use layouts in your ActionMailer views.

Connection Pooling - The connection pooling in Rails 2.2 allows Rails to distribute database requests across a pool of database connections. This can cause less lockups. In collaboration with a non-blocking MySQL driver, serious performance increases could result in certain situations.

Specify Join Table Conditions with Hashes - Do you need to run a find (or similar) query across a join? Now you can just specify the conditions for the joined tables in a hash, much like local tables conditions!

Limited Resource Routes - You can now limit map.resources to creating certain methods. For example, you might not want destroy or index methods - you can now specify these with :only and :except.

Memoization - Stop rolling your own memoization in Rails apps. Clemens Kofler demonstrates Rails 2.2's newly rolled-in memoization features. It's just a single method! If you have a view that calls on a calculated attribute often, this will give you some serious performance gains.

Custom Length Tokenizer for Validations - You can now specify a tokenizer of your own construction for validates_length_of validations.

Array#second through Array#tenth - If you're a bad programmer, you can now demonstrate it to the world by using the new Array#second, Array#third, Array#fourth, and so forth, methods. I've put it in my calendar to look for open source Rails apps using Array#seventh in six months time and to call them out on Rails Inside ;-)

Note: This list only takes into account some of the new features in Rails 2.2. There are a lot more! Read the release notes and the Rails 2.2 - What's New PDF to get the full picture.

Miscellaneous

restful-authentication-i18n - Want an authentication plugin for Rails 2.2 that supports internationalization? Take a look at result-authentication-i18n!

Barebones Apps - Check out Rails Inside's 7 Barebones Rails Apps to Kick Start Your Development Process.

Deploying on JBoss - You can now easily deploy a Rails app to a JBoss server. With Rails 2.2's significantly improved JRuby support, this makes rolling out Rails apps in the enterprise a breeze!

Installing Rails on Ubuntu Hardy Heron - Simon St Laurent has put together two Rails useful installation videos. One for servers, and one for the desktop.

REST for Rails 2 - Are you still in Rails 1.x land or not using REST at all? Would you like to? Geoffrey Grosenbach has put together a screencast showing you how it should be done.

A Better Rails Logo - The Rails Logo (as used at the head of this post) was created by Kevin Milden and is distrubuted under the BY-ND Creative Commons Licence. i personally like the older one.

Rails 2.2: Quick Feature list

Rails 2.2 was just released, and ryan strieks again with a great post.

let’s take a peek at some of the major new features (as determined by yours truly – feel free to pipe up with features that I’ve missed).

Rails 2.2.2 requires rubygems v 1.3.1, so before you upgrade make sure to do a sudo gem update --system.

Rails 2.2 Features

i am personnalt still on 2.1, and i don't think i will upgrade at this moment, but some features look very-needed in fact.


The Web Ask eizesus.com

Subscribe

    follow me on Twitter

    Twiters Around

    About Me

    My photo
    I am a web developer for more than 9 years, managed, cried, coded, designed and made money in this industry. now trying to do it again.

    Labels