<?xml version="1.0" encoding="UTF-8"?>
<posts type="array">
  <post>
    <body>&lt;p&gt;What is Rails and why would you want to use it over the myriad of other web application frameworks? From the website: Rails is a full-stack framework for developing database-backed web applications according to the Model-View-Control pattern.  However, the second question is much harder to answer and is at the heart of a much heated debate in the developer community.  Every developer has their favorite tool, framework, web server, text editor, etc&amp;#8230;  Moreover, the will vehemently defend their selection regardless of the faults of their platform of choice.&lt;/p&gt;
&lt;p&gt;In all honestly, I am just like other developers.  I have my favorites and I often find my self trying to deploy it no matter how inappropriate a choice it may be.  With my last design, I was finding Perl more and more of a hinderance than alleviating the workload.  That&amp;#8217;s not to say that Perl is not a great option for developing web software.  However, my choice of programming language (Perl) and framework (CGI::Application) were just not created for what I wanted to do.  Originally, I was very please at how lightweight CGI::Application was, but in the end, it was that fact that lead me to look elsewhere.&lt;/p&gt;
&lt;p&gt;Now there were plenty of other Perl frameworks for me to consider: Maypole, Catalyst and Jifty, Woodstock, and who knows how many others by now.  After all the Perl mantra is &lt;acronym title=&quot;there is more than one way to do it&quot;&gt;TIMTOWTDI&lt;/acronym&gt;.  So why did I abandon Perl?  David Cross sums up the main reasons in his post &lt;a href=&quot;http://www.oreillynet.com/onlamp/blog/2006/05/mvc_frameworks_in_perl.html&quot;&gt;MVC Frameworks in Perl&lt;/a&gt;, fragmentation.  All of these Perl frameworks work great in some niche areas and suck in others.  Having all these options is great in once sense as you can choose the tool that best fits your initial idea of what you need to accomplish.&lt;/p&gt;
&lt;p&gt;However, what I set out to do very rarely resembles my finished product and I often find myself struggling to accommodate my new vision with the set of restrictions I have imposed upon myself by selecting a certain tool.  I had a similar instance a few years ago when I switched my templating system from HTML::Template to Template::Toolkit.  My needs grew, and although I could accomplish them with my original choice, it be increasingly obvious that a different solution would be a better fit.  With Ruby, Rails is your only choice and because of that the ceiling of what you can accomplish is much higher.  However, although I have not yet hit it, there are plenty of people who have.&lt;/p&gt;
&lt;p&gt;So what is my impression of Ruby on Rails after creating my first real site?   Do I think it lived up to all the hype?  Yes and no.  I certinally can&amp;#8217;t deny that it is &lt;em&gt;very&lt;/em&gt; powerfuly MVC framework.  However, there are certain aspects, especially coming from the Perl developer community, that I found quite lacking.  First there is no Ruby equivalent of &lt;a href=&quot;http://www.perlmonks.org&quot;&gt;Perl Monks&lt;/a&gt;.  While similar sites do exist, such as &lt;a href=&quot;http://www.railsforum.com&quot;&gt;RailsForum&lt;/a&gt;, they are no where near as complete or active.  I would often post some perplexing problem and get a slew of high quality answers within the hour, sometime even big shots in the community itself (for instance perl Randal Schwartz, one of the authors of the Perl O&amp;#8217;Reilly books is an active member).  Second, I missed &lt;a href=&quot;http://www.cpan.org&quot;&gt;CPAN&lt;/a&gt;.  Rails plugins are found everywhere from RubyForge to the person svn servers of the developer.  However, I do believe that &lt;a href=&quot;http://www.github.com&quot;&gt;GitHub&lt;/a&gt; is going to change this fragmentation.  It is a great collaboration tool.&lt;/p&gt;
&lt;p&gt;Finally, all of the hype has caused a flow of developers to the platform, a large majority of whom are first time programmers.  Now a huge influx of developers is usually not a bad thing for any programming language, but because many of them are inexperienced, it makes it harder to find definitive answers.  Everyone is still searching for ways to do it themselves.  However, when this developer base matures, this will become a great asset.&lt;/p&gt;
&lt;p&gt;My website has always been a personal project designed for me to grow in my programming skills.  Throughout the years I had become very comfortable with Perl.  Unfortunately, with comfort comes stagnation.  By choosing Rails, I was in effect choosing to learn a whole new paradigm, programming language, and join a whole new developer environment.  I may eventually go back to Perl, but if my experience with designing this site are any indication of the future, I think I will be sticking with Ruby on Rails for quite some time.&lt;/p&gt;      <script type="text/javascript">
      var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
      </script>
      <script type="text/javascript">
      var pageTracker = _gat._getTracker("UA-4701682-1");
      pageTracker._initData();
      pageTracker._trackPageview();
      </script>
</body>
    <created-at type="datetime">2008-06-09T22:46:01Z</created-at>
    <id type="integer">1</id>
    <introduction>&lt;p&gt;There has been so much hype surrounding Ruby on Rails.  Even the mailing list for my beloved CGI:Application framework was being littered with posts comparing the two or about how to make thinks more railsesque.  But on the other hand, I had spent so much time coding my previous site engine in Perl and perfecting it that I didn&amp;#8217;t know if it would be worth the effort to learn a new platform, a new language with a different set of idioms, and rewrite &lt;em&gt;working&lt;/em&gt; code.  Well in about two months (my first commit was April 6th),  I have a working site that is nearly feature comparable (and in some cases far surpasses) with my previous design.  Rails &lt;strong&gt;really&lt;/strong&gt; is a very powerful web development platform.&lt;/p&gt;</introduction>
    <permalink>embracing-ruby-on-rails</permalink>
    <title>Embracing Ruby on Rails</title>
    <topic-id type="integer">1</topic-id>
    <updated-at type="datetime">2008-06-16T14:59:54Z</updated-at>
    <user-id type="integer">1</user-id>
    <version type="integer">1</version>
  </post>
  <post>
    <body>&lt;p&gt;Although the version of &lt;a href=&quot;http://prototype-ui.com/&quot;&gt;Prototype-UI&lt;/a&gt; that is currently available is considered a release candidate, I found their carousel to be quite stable. I have yet to try out some of their other components, but the autocomplete does look quite promising. You can start off by &lt;a href=&quot;http://prototype-ui.com/download/rc0/carousel.zip&quot;&gt;downloading&lt;/a&gt; the code (javascript and css files) from their  server. Once you have extracted the files, put the &lt;strong&gt;carousel.js&lt;/strong&gt; and &lt;strong&gt;prototype-ui.css&lt;/strong&gt; in your sites public folder. You can also copy their next/back buttons as well, but I went ahead and created my own.&lt;/p&gt;
&lt;p&gt;I am going to assume that you have some model that contains an array of photos. In this example that model is called &lt;code&gt;album&lt;/code&gt;. In your view that you want the image carousel, put in the following rhtml:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;multiline_code&quot;&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;horizontal_carousel&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;previous_button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;container&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;ta&quot;&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;&lt;span class=&quot;c&quot;&gt;&amp;lt;!-- AJAX WILL INSERT PHOTOS --&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;id&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;spinner&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;style&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;display: none;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;Loading ...&lt;span class=&quot;ta&quot;&gt;&amp;lt;br&lt;/span&gt; &lt;span class=&quot;ta&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
      &lt;span class=&quot;ta&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;class&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;next_button&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;script&lt;/span&gt; &lt;span class=&quot;an&quot;&gt;type&lt;/span&gt;=&lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;text/javascript&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;ta&quot;&gt;&amp;gt;&lt;/span&gt;
 // &lt;span class=&quot;er&quot;&gt;&amp;lt;&lt;/span&gt;![CDATA[
      function runTest() {
        carousel = new UI.Ajax.Carousel(&amp;quot;horizontal_carousel&amp;quot;,
          {url: &amp;quot;/albums/&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;&amp;lt;%=&lt;/span&gt; album.id &lt;span class=&quot;idl&quot;&gt;%&amp;gt;&lt;/span&gt;&lt;/span&gt;/elements&amp;quot;, elementSize: 140})
          .observe(&amp;quot;request:started&amp;quot;, function() {
                    $('spinner').show().morph(&amp;quot;opacity:0.8&amp;quot;, {duration:0.5});
            })
          .observe(&amp;quot;request:ended&amp;quot;, function() {
                    $('spinner').morph(&amp;quot;opacity:0&amp;quot;,
          {duration:0.5, afterFinish: function(obj) { obj.element.hide(); }});
            });
      }

      document.whenReady(runTest);
    // ]]&lt;span class=&quot;er&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;ta&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;ta&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The important thing to notice here is the value of the URL passed to the &lt;code&gt;UI.Ajax.Carousel&lt;/code&gt; function call. I have decided to call the method that returns the request images &lt;code&gt;elements&lt;/code&gt;. It is found in the &lt;code&gt;album&lt;/code&gt; controller and is expecting the id of the album that contains the photos to be displayed.&lt;/p&gt;
&lt;p&gt;Next we will update our album&amp;#8217;s controller. This is the part that gave me the most trouble. I orignally though I just had to supply the HTML that should be inserted inside the UL element, however after some digging I found out that it was actually accepting JSON. Luckly for us, it&amp;#8217;s not that hard using some Rails magick.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;multiline_code&quot;&gt;&lt;span class=&quot;r&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;fu&quot;&gt;elements&lt;/span&gt; 
  &lt;span class=&quot;iv&quot;&gt;@album&lt;/span&gt; = &lt;span class=&quot;co&quot;&gt;Album&lt;/span&gt;.find(params[&lt;span class=&quot;sy&quot;&gt;:id&lt;/span&gt;])

  count = &lt;span class=&quot;iv&quot;&gt;@album&lt;/span&gt;.photos.size - &lt;span class=&quot;i&quot;&gt;1&lt;/span&gt;
  to = [params[&lt;span class=&quot;sy&quot;&gt;:to&lt;/span&gt;].to_i, count].min
  from = params[&lt;span class=&quot;sy&quot;&gt;:from&lt;/span&gt;].to_i
  more = count != to ? &lt;span class=&quot;pc&quot;&gt;true&lt;/span&gt; : &lt;span class=&quot;pc&quot;&gt;false&lt;/span&gt;
  html = &lt;span class=&quot;iv&quot;&gt;@album&lt;/span&gt;.photos[from..to].collect { |photo| 
    &lt;span class=&quot;s&quot;&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;&amp;lt;li&amp;gt;&amp;lt;img src='&lt;/span&gt;&lt;span class=&quot;il&quot;&gt;&lt;span class=&quot;idl&quot;&gt;#{&lt;/span&gt;photo.public_filename(&lt;span class=&quot;sy&quot;&gt;:thumb&lt;/span&gt;)&lt;span class=&quot;idl&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;'&amp;gt;&amp;lt;/li&amp;gt;&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
  }

  data = { &lt;span class=&quot;sy&quot;&gt;:html&lt;/span&gt; =&amp;gt; html, &lt;span class=&quot;sy&quot;&gt;:from&lt;/span&gt; =&amp;gt; from, &lt;span class=&quot;sy&quot;&gt;:to&lt;/span&gt; =&amp;gt; to, &lt;span class=&quot;sy&quot;&gt;:more&lt;/span&gt; =&amp;gt; more }

  &lt;span class=&quot;c&quot;&gt;# Rails magick to get output in JSON format&lt;/span&gt;
  render &lt;span class=&quot;sy&quot;&gt;:json&lt;/span&gt; =&amp;gt; data.to_json
&lt;span class=&quot;r&quot;&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The last thing we need to do is update our routes file so that the path /albums/:id/elements is recognized by our Rails application. Add the following line to your routes.rb config file:&lt;br /&gt;
&lt;pre&gt;&lt;code class=&quot;multiline_code&quot;&gt;map.resources &lt;span class=&quot;sy&quot;&gt;:albums&lt;/span&gt;, &lt;span class=&quot;sy&quot;&gt;:member&lt;/span&gt; =&amp;gt; { &lt;span class=&quot;sy&quot;&gt;:elements&lt;/span&gt; =&amp;gt; &lt;span class=&quot;sy&quot;&gt;:get&lt;/span&gt; }&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;After a quick restart of your server (since we updated the routes file) and you should be ready to go!&lt;/p&gt;      <script type="text/javascript">
      var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
      document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
      </script>
      <script type="text/javascript">
      var pageTracker = _gat._getTracker("UA-4701682-1");
      pageTracker._initData();
      pageTracker._trackPageview();
      </script>
</body>
    <created-at type="datetime">2009-02-20T10:04:49Z</created-at>
    <id type="integer">15</id>
    <introduction>&lt;p&gt;I happened to be looking for a better way to show a preview of my web albums when I came across &lt;a href=&quot;http://prototype-ui.com/&quot;&gt;Prototype-UI&lt;/a&gt; which is a suite of user-interface components. Their carousel component was just want I need to spruce up my site design. The only problem was that documentation on the site is quite sparse and it took me a while to get things sorted out.&lt;/p&gt;</introduction>
    <permalink>creating-an-ajax-image-carousel</permalink>
    <title>Creating an AJAX Image Carousel</title>
    <topic-id type="integer">1</topic-id>
    <updated-at type="datetime">2010-01-15T13:17:38Z</updated-at>
    <user-id type="integer">1</user-id>
    <version type="integer">23</version>
  </post>
</posts>
