<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Our Geek Space &#187; ruby on rails</title>
	<atom:link href="http://blog.moove-it.com/category/ruby_on_rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.moove-it.com</link>
	<description>be free to express yourself...</description>
	<lastBuildDate>Thu, 26 Jan 2012 19:30:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>It&#8217;s about timing baby!</title>
		<link>http://blog.moove-it.com/its-about-timing-baby/</link>
		<comments>http://blog.moove-it.com/its-about-timing-baby/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 13:44:45 +0000</pubDate>
		<dc:creator>Andreas Fast</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=943</guid>
		<description><![CDATA[Yeah, it&#8217;s about timing. There was a problem in one of our projects at moove-it related to slow processing. There is a daemon spawning new threads to process certain new entries to the database. The entries come from a different system, that&#8217;s the reason for this program which processes each new entry. Sometimes at certain [...]]]></description>
			<content:encoded><![CDATA[<p>Yeah, it&#8217;s about timing.</p>
<p><a href="http://blog.moove-it.com/wp-content/uploads/2011/11/27169w0tgpcaxy.jpg" rel="lightbox[943]" title="Timing"><img class="size-medium wp-image-944 alignright" title="Timing" src="http://blog.moove-it.com/wp-content/uploads/2011/11/27169w0tgpcaxy-300x300.jpg" alt="" width="300" height="300" /></a></p>
<p>There was a problem in one of our projects at <a title="moove-it" href="http://moove-it.com" target="_blank">moove-it</a> related to slow processing. There is a daemon spawning new threads to process certain new entries to the database. The entries come from a different system, that&#8217;s the reason for this program which processes each new entry. Sometimes at certain hours of a day there are peaks in the entries to the database and the process will fall behind by about 20.000 entries or more. So we started analyzing the code to understand what was happening and why it took so long. We noted that each new thread the daemon spawned took about 5 seconds to complete its task. As we narrowed the measurement we came up with some code that took 5 seconds to execute but it only involved access to the database. So thanks to Aaron Patterson&#8217;s (<a title="@tenderlove" href="http://twitter.com/tenderlove" target="_blank">@tenderlove</a>) talk at RubyConf Uruguay about &#8220;Who makes the best asado&#8221; where he talked about rails and how it manages threads and database connections, we knew where to look.</p>
<p>What he explained is that each new thread requests its own database connection from the connection pool, and if there isn&#8217;t a free connection, rails waits for about 5 seconds and if after that there is no free connection it iterates over all the threads to take back the connections of dead threads(<a title="more info" href="http://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord/" target="_blank">more info</a>). See the correlation with the 5 seconds I talked about in the previous paragraph? We immediately suspected that this was the problem. So we started searching the Rails API for a way to release the connection at the end of each thread&#8217;s execution. Surprisingly, we didn&#8217;t find an easy and understandable explanation anywhere at first googling <img src='http://blog.moove-it.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> , so we digged deeper and came up with the following line:</p>
<blockquote><p>ActiveRecord::Base.connection_handler.clear_active_connections!</p></blockquote>
<p>The ActiveRecord::Base.connection_handler method returns the connection handler for the current thread and the clear_active_connections method does what it looks like, or from the Rails doc: &#8220;Returns any connections in use by the current thread back to the pool, and also returns connections to the pool cached by threads that are no longer alive.&#8221;</p>
<p>So this line returns the connections in use by a thread to the pool and enables the new threads spawned by the daemon to use the freed connections. This way we avoid the 5 second wait for rails to free the connections for us.</p>
<p>This one line picked up our performance from processing 1.000 entries in almost 2 hours to processing 10.000 in 5 minutes. Nice huh?!</p>
<p>That&#8217;s it. I&#8217;m not sure if this is the best way of doing it since this method also &#8220;&#8230; returns connections to the pool cached by threads that are no longer alive.&#8221; I guess this means it does the iteration over all the threads Aaron mentioned, but as you can see I&#8217;m happy with the performance improvement. We are using Rails 3.0.5, Aaron said that he will change the behavior, read more about it <a title="here" href="http://tenderlovemaking.com/2011/10/20/connection-management-in-activerecord/" target="_blank">here</a>.</p>
<p>Special thanks to <a title="@cheloeloelo" href="http://twitter.com/cheloeloelo" target="_blank">@cheloeloelo</a> who helped detecting the problems and digging through the Rails API finding the proper method to free the connections.</p>
<p><a href="http://www.freedigitalphotos.net/images/view_photog.php?photogid=151">Image: Suat Eman / FreeDigitalPhotos.net</a></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/its-about-timing-baby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Second RubyConf in Uruguay &#8211; 11th and 12th November</title>
		<link>http://blog.moove-it.com/second-rubyconf-in-uruguay-11th-12th-november/</link>
		<comments>http://blog.moove-it.com/second-rubyconf-in-uruguay-11th-12th-november/#comments</comments>
		<pubDate>Wed, 02 Nov 2011 01:19:45 +0000</pubDate>
		<dc:creator>Gabriela Isnardi</dc:creator>
				<category><![CDATA[moove-it]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[workshops]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyconf]]></category>
		<category><![CDATA[uruguay]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=900</guid>
		<description><![CDATA[We are sponsoring one of the greatest technology events here in Uruguay. The Second RubyConf taking place within less than two weeks, the 11th and 12th November 2011, where many IT experts from all over the world get together in order to be immersed in this dynamic world and and up to date get with [...]]]></description>
			<content:encoded><![CDATA[<p>We are sponsoring one of the greatest technology events here in Uruguay. The Second RubyConf taking place within less than two weeks, the 11th and 12th November 2011, where many IT experts from all over the world get together in order to be immersed in this dynamic world and and up to date get with the latest trends of Ruby and Agile methodologies.</p>
<p><a title="RubyConf Uruguay" href="http://rubyconfuruguay.org/" target="_blank">RubyConf Uruguay 2011</a></p>
<p>We are hungry for knowledge and refreshment, and we all want to be on the same train.</p>
<p>Please welcome all the new members to this awesome community. And help spreading the news, but even more important, do not miss the opportunity to meet the experts, discuss the future of RoR, and be Rail!</p>
<p><a href="http://blog.moove-it.com/wp-content/uploads/2011/11/newspaper-advertising-final-01-1024x710.jpg" rel="lightbox[900]" title="newspaper-advertising-final-01"><img class="alignleft size-large wp-image-901" title="newspaper-advertising-final-01" src="http://blog.moove-it.com/wp-content/uploads/2011/11/newspaper-advertising-final-01-1024x710.jpg" alt="" width="717" height="497" /></a></p>
<p>&nbsp;</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/second-rubyconf-in-uruguay-11th-12th-november/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby + Rails + Agile &#8211; sharing presentations</title>
		<link>http://blog.moove-it.com/ruby-rails-agile-sharing-presentations/</link>
		<comments>http://blog.moove-it.com/ruby-rails-agile-sharing-presentations/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 04:10:42 +0000</pubDate>
		<dc:creator>Martin Cabrera</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[moove-it]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[workshops]]></category>
		<category><![CDATA[ariel ludueña]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[gabriel chertok]]></category>
		<category><![CDATA[gianfranco zas]]></category>
		<category><![CDATA[martin cabrera]]></category>
		<category><![CDATA[ort]]></category>
		<category><![CDATA[pablo ifran]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[workshop]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=677</guid>
		<description><![CDATA[The last Wednesday we made a workshop in the ORT University. Pablo Ifran, Gianfranco Zas, Ariel Ludueña and I We share the presentations to everybody All_in_One_Agile_Development (in spanish) Ruby_and_Rails (in spanish)]]></description>
			<content:encoded><![CDATA[<p>The last Wednesday we made a workshop in the ORT University.<br />
Pablo Ifran, Gianfranco Zas, Ariel Ludueña and I</p>
<p>We share the presentations to everybody</p>
<p><a href="http://blog.moove-it.com/wp-content/uploads/2011/07/All_in_One_Agile_Development.pdf" target="_blank">All_in_One_Agile_Development</a> (in spanish)</p>
<p><a href="http://blog.moove-it.com/wp-content/uploads/2011/07/Ruby_and_Rails.pdf" target="_blank">Ruby_and_Rails</a> (in spanish)</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/ruby-rails-agile-sharing-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Workshop of Ruby + Ruby on Rails + SCRUM at ORT University &#8211; July 6, 2011</title>
		<link>http://blog.moove-it.com/workshop-of-ruby-ruby-on-rails-scram-at-ort-university-july-6-2011/</link>
		<comments>http://blog.moove-it.com/workshop-of-ruby-ruby-on-rails-scram-at-ort-university-july-6-2011/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 14:24:01 +0000</pubDate>
		<dc:creator>Martin Cabrera</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[talks]]></category>
		<category><![CDATA[workshops]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[agile development]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[ort]]></category>
		<category><![CDATA[workshop]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=663</guid>
		<description><![CDATA[Moove-IT is now part of the Ruby on Rails Workshops and Conferences around the world. Even when Ruby seems to be the most popular modern programming language in America, there was nowhere in Uruguay you could actually learn it. Moove-IT will give you a heads up on this exciting language and Rails framework on July [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Moove-IT is now part of the Ruby on Rails Workshops and Conferences around the world.</strong></p>
<p>Even when Ruby seems to be the most popular modern programming language in America, there was nowhere in Uruguay you could actually learn it. Moove-IT will give you a heads up on this exciting language and Rails framework on July 6, 2011 (please see ad below).</p>
<p>This will be the first in a series of workshops focusing on Ruby, RoR, Scrum and hands on training exercises.</p>
<p>We are so proud to have made so much progress working with this technology and methodology that we feel the need to contribute to the local Ruby community.</p>
<p>Join us! Be part.</p>
<p><a href="http://blog.moove-it.com/wp-content/uploads/2011/06/taller-scrum-v5.jpg" target="_blank" rel="lightbox[663]" title="workshop Ruby on Rails"><img class="alignleft size-large wp-image-664" title="workshop Ruby on Rails" src="http://blog.moove-it.com/wp-content/uploads/2011/06/taller-scrum-v5-1024x723.jpg" alt="" width="738" height="521" /></a></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/workshop-of-ruby-ruby-on-rails-scram-at-ort-university-july-6-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on rails for mobiles</title>
		<link>http://blog.moove-it.com/ruby-on-rails-for-mobiles/</link>
		<comments>http://blog.moove-it.com/ruby-on-rails-for-mobiles/#comments</comments>
		<pubDate>Fri, 06 May 2011 22:25:45 +0000</pubDate>
		<dc:creator>sebastian.sassi</dc:creator>
				<category><![CDATA[ipad]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[web 2.0]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=607</guid>
		<description><![CDATA[Time ago, one of our customers asked us to implement a new web project with support for smartphones. The objective was to support the most common operating systems: iOS, android, blackberry, symbian, with the possibility of using the phone capabilities (gps, sound and vibration). After researching on different frameworks and technologies we have arrived to [...]]]></description>
			<content:encoded><![CDATA[<p>Time ago, one of our customers asked us to implement a new web project with support for smartphones. The objective was to support the most common operating systems: iOS, android, blackberry, symbian, with the possibility of using the phone capabilities (gps, sound and vibration).<br />
After researching on different frameworks and technologies we have arrived to some conclusions that I would like to share with people who have had the same dilemma of choosing a good framework to use.<br />
I must say that this research was based on data taken from different sources (both official and unofficial), and also having taken some particular decisions while evaluating the alternatives, that do not have to match with your own criteria.</p>
<p>First of all, we classified the available options into two different categories:</p>
<ul>
<li>&#8216;Native&#8217; Development frameworks: Rhodes, NimbleKit, Titanium (this is new to the list), PhoneGap</li>
<li>Javascript libraries: Sencha, JQTouch, JQuery mobile</li>
</ul>
<p><strong>Rhodes</strong></p>
<p>According to the official description, The Rhodes application framework allows developers to create native mobile applications with portability of editing HTML templates and the power of the Ruby programming language. Applications written in Rhodes exhibit the performance and richness of apps written to the native device operating systems with local data but enable developers to have the productivity of web interfaces in HTML. Developers write their applications once and they then run on all major mobile device operating systems: iPhone, Windows Mobile, Blackberry and more.</p>
<p>Advantages:</p>
<ul>
<li>Programming in Ruby</li>
<li>Full access to the Device API (Application looks different in each device)</li>
<li>Several devices supported: IPhone, BlackBerry, Android, Windows mobile</li>
<li>RhoSync: RhoSync retrieves data via web services (REST or SOAP) from backend enterprise applications for distribution to downstream mobile devices.</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Licensing: It is a commercial product. Costs arround U$S 500 per project.</li>
</ul>
<p><strong>NimbleKit</strong></p>
<p>NimbleKit says that it is a framework to create applications for iPhone and iPod touch fast. Programmers do not need to know Objective-C or iPhone SDK. All they need is to know how to write an HTML page with Javascript code.</p>
<p>Advantages:</p>
<ul>
<li>HTML, CSS &amp; Javascript</li>
</ul>
<p>Disadvantages</p>
<ul>
<li>It only works for iphone, ipods &amp; ipads.</li>
</ul>
<p><strong>Titanium &amp; PhoneGap</strong></p>
<p>From architectural standpoint, these two frameworks are very similar. Titanium and PhoneGap expose the smartphone features through a set of Javascript APIs, while the application’s logic (html, css, javascript) runs inside a native WebView control. Through the javascript APIs, the “web app” has access to the mobile phone functions such as Geolocation, Accelerometer Camera, Contacts, Database, File system, and so on.</p>
<p>The differences:</p>
<p>PhoneGap does not expose the native UI components to javascript. Titanium, on the other hand, has a comprehensive UI API that can be called in javascript to create and control all kinds of native UI controls. Utilizing these UI APIs, a Titanium app can look more “native” than a PhoneGap app. Second, PhoneGap supports more mobile phone platforms than Titanium does. PhoneGap APIs are more generic and can be used on different platforms such as iPhone, Android and Blackberry. Titanium is primarily targeting iPhone and Android. Some of its APIs are platform specific (like the iPhone UI APIs). The use of these APIs will reduce the cross-platform capability of your application.<br />
If your concern for your app is to make it more “native” looking, Titanium is a better choice. If you want to be able to “port” your app to another platform more easily, PhoneGap will be better.</p>
<p>Advantages:</p>
<ul>
<li>Multi device</li>
<li>Programming in HTML, CSS &amp; Javascript</li>
<li>MIT License</li>
</ul>
<p>Disadvantages:</p>
<ul>
<li>Some devices native features are not exposed in the API</li>
</ul>
<p><strong>Sencha</strong></p>
<p>According to the official documentation, Sencha Touch is the first app framework built specifically to leverage HTML5, CSS3, and Javascript for the highest level of power, flexibility, and optimization. They make specific use of HTML5 to deliver components like audio and video, as well as a localStorage proxy for saving data offline. They have made extensive use of CSS3 in our stylesheets to provide the most robust styling layer possible.<br />
Altogether, the entire library is under 80kb (gzipped and minified), and it is trivial to make that number even smaller by disabling unused components or styles.</p>
<p>Advantages</p>
<ul>
<li>Great UI Controls</li>
<li>Multi device</li>
</ul>
<p>Disadvantages</p>
<ul>
<li>Commercial license (U$S 1.800 for 5 developers)</li>
</ul>
<p><strong>JQTouch</strong><br />
It is &#8220;A jQuery plugin for mobile web development on the iPhone, iPod Touch, and other forward-thinking devices.&#8221; [1]</p>
<p>Advantages</p>
<ul>
<li>Great UI Controls</li>
<li>Multi device</li>
<li>MIT License</li>
</ul>
<p>Disadvantages</p>
<ul>
<li>Is focused on small screen devices</li>
<li>It&#8217;s a jquery plugin</li>
<li>It was created in 2009 by David Kaneda and has been relatively quiet until release of beta 3 (April 24th 2011).</li>
</ul>
<p><strong>JQuery Mobile</strong><br />
It is a unified user interface system across all popular mobile device platforms, built on jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily themeable design.</p>
<p>Advantages</p>
<ul>
<li>Multi device (See <a href="http://jquerymobile.com/gbs/">http://jquerymobile.com/gbs/</a>) (supports much more devices than JQTouch)</li>
<li>Very simple to use</li>
<li>John Resig, JQuery&#8217;s founder is one of the main developers and it is a high activity project</li>
<li>It is not a jquery plugin, it is a new framework</li>
<li>Dual licensed under MIT and GPL Version 2</li>
</ul>
<p>Disadvantages</p>
<ul>
<li>It is still in Alpha version</li>
</ul>
<p><strong>CONCLUSION</strong><br />
After evaluating the different frameworks, we arrived at the next conclusions:<br />
We should use a framework that generates html + css + js, because this technology guarantees a long term support on different devices<br />
We should use a framework that supports access to devices specific capabilities (i.e. sound, gps, camera, vibration, data, etc.) in case we need them in a near future<br />
Because we prefer unrestrictive licenses (MIT, BSD, LGPL and others) our options are reduced to: PhoneGap, Titanium &amp; JQTouch.</p>
<p>Finally, we choose <strong>PhoneGap + JQuery mobile</strong> because they are open technologies and support multiple platforms. Also, resulting interfaces are similar across different devices and that is a desired feature for our users.<br />
JQTouch and JQuery mobile are awesome frameworks to develop mobile applications, but we prefer to choose JQuery Mobile since it support much more devices (altough it is in alpha version), has high activity and is not just optimized for WebKit as jQtouch does.<br />
We also think that JQuery Mobile is pretty easy to use, the resulting interfaces are usable and has many components to use.</p>
<p>The rest of the story is pretty easy ( just because we use Ruby on Rails <img src='http://blog.moove-it.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  ), you should create some helpers that adds the JQuery Mobile features to the pages, or use some existent plugin, you can find a starting guide here: <a href="http://goo.gl/5Soyq">http://goo.gl/5Soyq</a>.</p>
<p>I hope you find this post useful, have a nice coding!</p>
<p>[1]: forward-thinking: Someone who is forward-thinking is thinking progressively and possesses the ability to look beyond the &#8220;now&#8221; and formulate strategies for future success. They are constantly asking &#8220;what&#8217;s next?&#8221;.</p>
<p>Sources:</p>
<ul>
<li><a href="http://www.phonegap.com/">http://www.phonegap.com/</a></li>
<li><a href="http://www.nimblekit.com/">http://www.nimblekit.com/</a></li>
<li><a href="http://rhomobile.com/">http://rhomobile.com/</a></li>
<li><a href="http://www.jqtouch.com/">http://www.jqtouch.com/</a></li>
<li><a href="http://jquerymobile.com/">http://jquerymobile.com/</a></li>
<li><a href="http://www.sencha.com/products/touch/">http://www.sencha.com/products/touch/</a></li>
<li><a href="http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/">http://fuelyourcoding.com/getting-started-with-jquery-mobile-rails-3/</a></li>
</ul>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/ruby-on-rails-for-mobiles/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sass why is useful</title>
		<link>http://blog.moove-it.com/sass-why-is-useful/</link>
		<comments>http://blog.moove-it.com/sass-why-is-useful/#comments</comments>
		<pubDate>Fri, 26 Nov 2010 18:52:04 +0000</pubDate>
		<dc:creator>Pablo Ifran</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sass]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web sites]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[styles]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=545</guid>
		<description><![CDATA[Sass is used for generating css files based on his own syntax, it&#8217;s very useful because allows you to avoid repeating code across the different scss files using import (allows you to import code from other scss file), or mixins(scss functions). Also, allows you to write varibles, for using in different scss, this makes easier [...]]]></description>
			<content:encoded><![CDATA[<p>Sass is used for generating css files based on his own syntax, it&#8217;s very useful because allows you to avoid repeating code across the different scss files using import (allows you to import code from other scss file), or mixins(scss functions). Also, allows you to write varibles, for using in different scss, this makes easier to do different templates based on colors or images for example.</p>
<p>_sprites.scss</p>
<pre>
@mixin sprite_for($image_class, $x, $y, $image: "/images/sprite_image.png") {
&nbsp;&nbsp;.sprite_image.#{$image_class} {
&nbsp;&nbsp;&nbsp;&nbsp;background: transparent url($image) no-repeat scroll $x $y;
&nbsp;&nbsp;&nbsp;&nbsp;height:16px;
&nbsp;&nbsp;&nbsp;&nbsp;width:16px;
&nbsp;&nbsp;}
}
_images.scss</pre>
<pre>$my_sprite_image_path: "/images/my_sprite_image_path.png";
</pre>
<p>default.scss</p>
<pre>
@import "sprites", "images";

@include sprite_for("my_image", 0, 0, $my_sprite_image_path);
</pre>
<p>That generates</p>
<p>default.css</p>
<pre>
&nbsp;&nbsp;.sprite_image.my_image {
&nbsp;&nbsp;&nbsp;&nbsp;background: transparent url(/images/my_sprite_image_path.png) no-repeat scroll 0 0;
&nbsp;&nbsp;&nbsp;&nbsp;height:16px;
&nbsp;&nbsp;&nbsp;&nbsp;width:16px;
&nbsp;&nbsp;}
</pre>
<p>So, this is best sorted using this method, because you have the image path in a single file and you use it in other files only by importing the file with the images path, it&#8217;s also simpler to remove an image because you only need to find the references to that variable and delete them.</p>
<p>The sass framework also allows you to use the DRY principle because you can write nested selector, I&#8217;ll show you with an example:</p>
<p>default.scss</p>
<pre>
.some_class {
&nbsp;&nbsp;width: 100px;
&nbsp;&nbsp;.some_other_class {
&nbsp;&nbsp;&nbsp;&nbsp;display: block;
&nbsp;&nbsp;}
}
</pre>
<p>default.css</p>
<pre>
.some_class {width:100px;}
.some_class .some_other_class {display:block;}
</pre>
<p>Doesn&#8217;t affect the performance because it generates a css file at development time.</p>
<p>It also allows you to benefit from some of the advantages of css 3 right now.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/sass-why-is-useful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Juggernaut: Chat on Rails</title>
		<link>http://blog.moove-it.com/juggernaut-chat-on-rails/</link>
		<comments>http://blog.moove-it.com/juggernaut-chat-on-rails/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 14:01:52 +0000</pubDate>
		<dc:creator>ivan.etchart</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[web 2.0]]></category>
		<category><![CDATA[web sites]]></category>
		<category><![CDATA[channel]]></category>
		<category><![CDATA[chat]]></category>
		<category><![CDATA[chat on rails]]></category>
		<category><![CDATA[juggernaut]]></category>
		<category><![CDATA[private]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=466</guid>
		<description><![CDATA[To implement chat on Rails we need the Juggernaut gem. The newest version of Juggernaut is build upon nodeJS. 1. Install Juggernaut: First, install nodejs (http://nodejs.org), redis (http:/code.google.com/p/redis/) and Juggernaut gem (gem install juggernaut). Then download server git clone &#8230; 2. Integrate with Rails to implement chat! After Juggernaut gem is installed, add it to [...]]]></description>
			<content:encoded><![CDATA[<div lang="x-western">
<div>
<div id="_mcePaste">To implement chat on Rails we need the Juggernaut gem. The newest version of Juggernaut is build upon nodeJS.</div>
<div id="_mcePaste"><strong>1. Install Juggernaut:</strong></div>
<div id="_mcePaste">First, install nodejs (http://nodejs.org), redis (http:/code.google.com/p/redis/) and Juggernaut gem (gem install juggernaut).</div>
<div id="_mcePaste">Then download server git clone &#8230;</div>
<div id="_mcePaste"><strong>2. Integrate with Rails to implement chat!</strong></div>
<div id="_mcePaste">After Juggernaut gem is installed, add it to environment.rb:</div>
<div id="_mcePaste">
<pre>config.gem "juggernaut"</pre>
</div>
<div id="_mcePaste">Suppose you have a system with user authentication, the idea is to generate an environment where you&#8217;re able to chat with other users and see to what extent features can be added in order to create an awesome chat!</div>
<div id="_mcePaste"><em>Note: Providing a step by step guide to create a working chat isn&#8217;t the idea of this tutorial. It&#8217;s to show different possibilites to develop on</em></div>
<div><em> Juggernaut.</em></div>
<div><em><br />
</em></div>
<div id="_mcePaste"><strong>Connecting to Juggernaut from Rails</strong></div>
<div><strong><br />
</strong></div>
<div id="_mcePaste">It&#8217;s necessary to add the file WebSocketMain.swf to the public folder. This hasn&#8217;t to be exactly this way, you can change its location, but if you do, then you&#8217;ll have to change the WEB_SOCKET_SWF_LOCATION, due to an issue with Firefox (&#8230; for further information visit juggernaut git page).</div>
<div id="_mcePaste">Juggernaut serves every file necessary for running by default, so you can leave them on the server where Jaggernaut is installed and configure everything in your client (mainly due to Firefox) in order to avoid adding extra files to your project.</div>
<div id="_mcePaste">Add to your view this line:</div>
<div id="_mcePaste">
<pre>&lt;script src="http://localhost:8080/application.js" type="text/javascript" charset="utf-8"&gt;&lt;/script&gt;</pre>
</div>
<div id="_mcePaste"><em>Note : you can add this file in another way or eventually add it to your project if you want.</em></div>
<div id="_mcePaste"><em>Inside another script tag:</em></div>
<div><em><br />
</em></div>
<div id="_mcePaste">
<pre>var jugger = new Juggernaut;</pre>
</div>
<div id="_mcePaste"><strong>** Connection events provided by Juggernaut</strong></div>
<div id="_mcePaste">Juggernaut provides you with three different events : Connect, Disconnect o Reconnect.</div>
<div>
<pre>jugger.on("connect - disconnect - reconnect", callback)</pre>
</div>
<div id="_mcePaste">You can use this events to implement whatever function you want to execute, i.e. alerting when a client has connected:</div>
<pre>jug.on("connect", function() {alert("I'm connected!!");});</pre>
<div id="_mcePaste">At this point you have the connection of your client ready, you can test it, you have to start Juggernaut. * First run redis :</div>
<div id="_mcePaste">
<pre>./redis-server redis.conf</pre>
<p>(whereever you have installed it) *</p>
</div>
<div id="_mcePaste">Then go to the folder where you&#8217;ve downloaded the server to and run juggernaut:</div>
<div id="_mcePaste">
<pre>node server.js</pre>
</div>
<div id="_mcePaste">
<strong>Let&#8217;s chat!</strong></div>
<div id="_mcePaste">Now that we have everything going, would be a good time to start chatting.</div>
<div id="_mcePaste">First you need to subscribe to a channe. Inside the channel you&#8217;ll be able to connect and user messages scope is restricted to channel.</div>
<div id="_mcePaste">Then :</div>
<div id="_mcePaste">
<pre> jug.subscribe("name_or_channel_id", function(data) { .. here you'll handle all messages coming from channel ... })</pre>
</div>
<div id="_mcePaste">Clarifying a bit&#8230; with this function we subscribe to the channel and can pass a function as a parameter to handle data coming from it, i.e. any user&#8217;s messages, let&#8217;s give an example:</div>
<div id="_mcePaste">First you need to have a div tag with an id (id_div), what you want is to append a list element containing message content to the div element everytime someone sends a message.</div>
<div id="_mcePaste">
<pre>jug.subscribe("name_or_channel_id", function(data){
var li = $("&lt;li /&gt;");
li.text(data);
$("#id_div").append(li);
});</pre>
</div>
<div id="_mcePaste">You can have a div or textearea element, adding text to a textarea element is relatively simpler, it&#8217;s enough to do</p>
<pre>textarea.value += (data + "\n");</pre>
<p>but you&#8217;ll lose customizing power. li elements can be enriched with style, making the chat more attractive.</p>
</div>
<div id="_mcePaste">You&#8217;ve received data and added to a div element, but you&#8217;re still unable to send data. Let&#8217;s setup a form:</div>
<div id="_mcePaste">
<pre>&lt;% form_remote_tag(:url =&gt; path_to_send_message_method, :success =&gt; "$('#msg_body').value=''" do &gt;
&lt;= text_field_tag 'msg_body', '', :size =&gt; '50' &gt;
&lt;= submit_tag 'Send Message' &gt;
&lt;% end %&gt;</pre>
</div>
<div id="_mcePaste">And the method :</div>
<div id="_mcePaste">
<pre>def send_message
Juggernaut.publish("name_or_channel_id", parse_chat_message(params[:msg_body], current_user))
end</pre>
</div>
<div id="_mcePaste">parse_chat_message? &#8230; Yes, before publishing data, you can process it and why not modify it a bit.</div>
<div id="_mcePaste">
<pre>def parse_chat_message(msg, user)
return "#{user.login} says: #{msg}"
end</pre>
</div>
<div id="_mcePaste">We are sending information to Juggernaut with this format : &#8216;usuario says: something&#8217;</div>
<div id="_mcePaste">Done!, you have your server up and running, and know how to send and receive data, there&#8217;s nothing else to try.</div>
<div id="_mcePaste">
<strong>Extras:</strong></div>
<div id="_mcePaste"><em>Private chat case :*</em></div>
<div><em><br />
</em></div>
<div id="_mcePaste">You can&#8217;t call a chat a chat if you can&#8217;t have a private conversation with someone. A good way of implementing this, is subscribing your users to a particular chatroom identified by user&#8217;s id. Simple add another subscribe:</div>
<div id="_mcePaste">
<pre> jug.subscribe("name_or_channel_id", function(data){ .. handle private message .. }</pre>
</div>
<div id="_mcePaste">The receiving user must be able to subscribe to your chat and send messages to you.</div>
<div id="_mcePaste">To achive that, you should write a function that when you click on the user you want to send a private message to, subscribes to its chatroom and allows you to send messages to the user. This can be implemented in many different ways! You&#8217;ll have to simply make your choice according to your needs!</div>
</div>
<div>
<pre><script src="&lt;a href="><!--mce:0--></script></pre>
</div>
</div>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/juggernaut-chat-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails 3: New features &amp; Changes</title>
		<link>http://blog.moove-it.com/rails-3-new-features-changes/</link>
		<comments>http://blog.moove-it.com/rails-3-new-features-changes/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 18:39:31 +0000</pubDate>
		<dc:creator>Michel Golffed</dc:creator>
				<category><![CDATA[moove-it]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=470</guid>
		<description><![CDATA[In this post I&#8217;ll show you some basic examples about the new features and changes of the web framework Rails 3, for this I’ll use two models: User and Task, having a relationship between them where a User has_many :tasks. ActiveRecord finder methods Let&#8217;s start by finding the five most recently created users: Rails 2 [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll show you some basic examples about the new features and changes of the web framework Rails 3, for this I’ll use two models: User and Task, having a relationship between them where a User has_many :tasks.</p>
<div id="_mcePaste">
<h3>ActiveRecord finder methods</h3>
</div>
<div id="_mcePaste">Let&#8217;s start by finding the five most recently created users:</div>
<p><strong> </strong></p>
<div id="_mcePaste"><strong>Rails 2</strong></div>
<p><strong> </strong></p>
<p><strong> </strong></p>
<pre>User.find(:all, : order =&gt; "created_at desc", :limit =&gt; 5)</pre>
<div>What&#8217;s new about this method call in rails 3?</div>
<div id="_mcePaste">Rails 3 looks at the hash of options that is being passed to find(:all, : order, and :limit) and replace each item in the hash with an equivalent method.</div>
<p><strong> </strong></p>
<div><strong>New API methods:</strong></div>
<p><strong> </strong></p>
<p><strong> </strong></p>
<pre>
<div id="_mcePaste">where, having, select, group, order, limit, offset, joins, includes, ...</div>
</pre>
<div id="_mcePaste">So, in <strong>Rails 3</strong> this becomes:</div>
<pre>
<div id="_mcePaste">User.order("created_at desc").limit(5)</div>
</pre>
<div id="_mcePaste">Let&#8217;s continue with this second example:</div>
<div id="_mcePaste"><strong>Rails 2:</strong></div>
<pre>
<div id="_mcePaste">User.find(:all, :conditions =&gt; ["created_at &lt;= ?", Time.now], :include =&gt; :tasks)</div>
</pre>
<div id="_mcePaste"><strong>Rails 3</strong>:</div>
<pre>
<div id="_mcePaste">User.where("created_at &lt;= ?", Time.now).includes(:tasks)</div>
</pre>
<div id="_mcePaste">In this example the &#8220;where&#8221; method substitutes the :conditions parameter.</div>
<h3>
<div id="_mcePaste">Named Scopes</div>
</h3>
<div id="_mcePaste">Changes to named_scopes in Rails 3:</div>
<div id="_mcePaste">User model in <strong>rails 2</strong> with two named scopes:</div>
<pre>
<div id="_mcePaste">class User &lt; ActiveRecord::Base</div>
<div id="_mcePaste">named_scope :active, :conditions =&gt; '!is_deleted'</div>
<div id="_mcePaste">named_scope :south_american,</div>
<div id="_mcePaste">:conditions =&gt; ["nationality IN (?)", Nationality::south_american_countries]</div>
<div id="_mcePaste">end</div>
</pre>
<div id="_mcePaste">The same in <strong>rails 3</strong> would be:</div>
<pre>
<div id="_mcePaste">class User &lt; ActiveRecord::Base</div>
<div id="_mcePaste">scope :active, where('!is_deleted')</div>
<div id="_mcePaste">scope :south_american,</div>
<div id="_mcePaste">where("nationality IN (?)", Nationality::south_american_countries)</div>
<div id="_mcePaste">end</div>
</pre>
<div id="_mcePaste">Note that the method that we use to define as named_scope has become to just &#8220;scope&#8221;. Also, we no longer pass the conditions as a hash but, as with find, we use methods.</div>
<div id="_mcePaste"></div>
<div><strong>Chainability</strong></div>
<div><strong><br />
</strong></div>
<div id="_mcePaste">Another new feature is the ability to build up scopes. If we want to create a scope called &#8220;recent&#8221;, that will return the most recently created active south american users ordered by their creation date, we can do so by reusing the two scopes we already have.</div>
<div id="_mcePaste">Chaining together the two scopes we already have and add an order method to create the new scope, is all we need to do.</div>
<div id="_mcePaste">Here is the result:</div>
<pre>
<div id="_mcePaste">scope :recent, active.south_american.order("created_at desc")</div>
</pre>
<div id="_mcePaste">
<h3>ActiveRecord Validation</h3>
</div>
<div id="_mcePaste">Separate validations in <strong>Rails 2</strong></div>
<pre>
<div id="_mcePaste">validates_presence_of :email</div>
<div id="_mcePaste">validates_uniqueness_of :email</div>
<div id="_mcePaste">validates_length_of :email, :maximum =&gt; 30</div>
</pre>
<div id="_mcePaste">All validations together for a field in <strong>Rails 3</strong></div>
<pre>
<div id="_mcePaste">validates :email, :presence =&gt; true,</div>
<div id="_mcePaste">:uniqueness =&gt; true,</div>
<div id="_mcePaste">:length =&gt; {:maximum =&gt; 30}</div>
</pre>
<div id="_mcePaste">Hope you enjoyed it, some other features of Rails 3 will be published on upcoming posts.</div>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/rails-3-new-features-changes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bullet: a gem to help reduce N+1 queries</title>
		<link>http://blog.moove-it.com/bullet-a-gem-to-help-reduce-n1-queries/</link>
		<comments>http://blog.moove-it.com/bullet-a-gem-to-help-reduce-n1-queries/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 21:19:07 +0000</pubDate>
		<dc:creator>Lucía Escanellas</dc:creator>
				<category><![CDATA[performance]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=438</guid>
		<description><![CDATA[Bullet is a plugin written by Richard Huang, that helps reducing the number of queries an application makes. It was first posted on 2009, but it is still a pretty useful gem to monitor your application for performance improvements. It has several ways of notifying problems: by Growl notifications, JavaScript alerts by default, and even [...]]]></description>
			<content:encoded><![CDATA[<p>Bullet is a plugin written by Richard Huang, that helps reducing the number of queries an application makes. It was first posted on 2009, but it is still a pretty useful gem to monitor your application for performance improvements.<br />
It has several ways of notifying problems: by Growl notifications, JavaScript alerts by default, and even using XMPP too. Additionally, it saves on its own bullet.log the exact line and stack trace of what caused the alert, and if you want to, it can also write to the application log.<br />
<br />
The project is on GitHub: <a href="http://github.com/flyerhzm/bullet">http://github.com/flyerhzm/bullet </a></p>
<p>You are probably familiar with the N+1 query and cache counter problems, so let&#8217;s look how Bullet will detect these by monitoring the database queries.</p>
<p><strong>The N+1 query problem</strong></p>
<p>Suppose we have our application with accounts having many rate plans:</p>
<p><code> </code></p>
<pre>class RatePlan &lt; ActiveRecord::Base
  belongs_to :account
end
</pre>
<p>If we iterate over the rate plans, accessing rate plans attributes, like:</p>
<p><code> </code></p>
<pre>RatePlan.all.each {
  |post| puts "#{rate_plan.name}, by #{rate_plan.account.name}"
}</pre>
<p>Will be using N+1 queries:</p>
<ul>
<li> one query to get all the rate plans</li>
<li>then, for each rate plan, one query to get the corresponding account.</li>
</ul>
<p>(This means that if we have 1000 posts, we&#8217;ll be doing 1000+1 queries)</p>
<p>By using the :include option, we can retrieve the rate plans and their corresponding accounts on the same query:</p>
<pre>RatePlan.find(:all, :include =&gt; :account).each {
   |post| puts "#{rate_plan.name}, by #{rate_plan.account.name}"
}</pre>
<p>By detecting if we forgot to use eager loading or a counter cache, Bullet can save time looking for problems on the fly.<br />
For example, Bullet will show this message:</p>
<p style="text-align: center"><a href="http://blog.moove-it.com/wp-content/uploads/2010/11/message.png" rel="lightbox[438]" title="Bullet: a gem to help reduce N+1 queries"><img class="size-medium wp-image-439 aligncenter" src="http://blog.moove-it.com/wp-content/uploads/2010/11/message-300x104.png" alt="N+1 Query Detected Message" width="300" height="104" /></a></p>
<p>We have to be careful not to abuse the :include option. If the rate_plans table is big enough, it could take too much server memory. Also, we could end up with big, slow requests, or getting from the server a lot of data that won&#8217;t be used. Bullet will show a message if it detects an unused eager loading.</p>
<p><strong>Cache counters</strong></p>
<p>Cache counters is another improvement in a one-to-many relationship. Because the _has_many_ relationship defines an attribute that is a collection, if we use the size property on this attribute, it will trigger a select count(*) on the child table. This is generally acceptable, except when we are using frequently count and we end up going to the database unnecessarily.<br />
In order to avoid that, we can use counter caching: Active Record will maintain for a parent table the number of child references. Bullet also shows a message if it finds a cache counter is needed.</p>
<p><strong>Configuration</strong></p>
<p>You have to first install the gem, by adding it to the Gemfile, or by installing manually:</p>
<p><code> </code></p>
<pre>sudo gem install bullet --pre</pre>
<p>The next thing is to add some configuration to the development environment. Bullet won&#8217;t do anything unless you configure it explicitly, and also note that it&#8217;s not a good idea to configure it on the production environment, because on that case your users would also receive those N+1 query alerts.</p>
<p>Configuration allows Growl notifications, and sending messages by XMPP (Jabber), but since the default JavaScript alerts are good enough for me, I configured it like this:</p>
<p><code> </code></p>
<pre>config.after_initialize do
  Bullet.enable = true
  Bullet.alert = true
  Bullet.bullet_logger = true
  Bullet.console = true
  Bullet.growl = false
  Bullet.rails_logger = true
  Bullet.disable_browser_cache = true
end</pre>
<p>Note the last option, because disabling browser cache can save you some trouble on some configurations. In any case, if Bullet is not working, try first disabling browser cache.</p>
<p>With this configuration, it will show a JavaScript alert, the same message on the console, and the detail and stack trace on the bullet.log.</p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/bullet-a-gem-to-help-reduce-n1-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails security</title>
		<link>http://blog.moove-it.com/rails-security/</link>
		<comments>http://blog.moove-it.com/rails-security/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 11:30:53 +0000</pubDate>
		<dc:creator>Pablo Ifran</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[production]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://blog.moove-it.com/?p=378</guid>
		<description><![CDATA[When you are working with svn (pulling your project from the svn to the web server) and you want to deploy a system into production with apache (mod_rails), you must filter the svn folders (to prevent that other users view your svn files). To do that task, you must add the following lines to the [...]]]></description>
			<content:encoded><![CDATA[<p>When you are working with svn (pulling your project from the svn to the web server) and you want to deploy a system into production with apache (mod_rails), you must filter the svn folders (to prevent that other users view your svn files).</p>
<p>To do that task, you must add the following lines to the apache configuration.</p>
<p><code><br />
&lt;DirectoryMatch "^/.*/\.svn/"&gt;<br />
&nbsp;&nbsp;ErrorDocument 403 /404.html<br />
&nbsp;&nbsp;Order allow,deny<br />
&nbsp;&nbsp;Deny from all<br />
&nbsp;&nbsp;Satisfy All<br />
&lt;/DirectoryMatch&gt;<br />
</code></p>
<!-- PHP 5.x -->]]></content:encoded>
			<wfw:commentRss>http://blog.moove-it.com/rails-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

