<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Ruby on Rails</title>
        <link>http://geekswithblogs.net/alternativedotnet/category/8620.aspx</link>
        <description>Ruby on Rails</description>
        <language>en-US</language>
        <copyright>Michel Grootjans</copyright>
        <managingEditor>michel.grootjans@gmail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Why I like Ruby on Rails: Part 1</title>
            <link>http://geekswithblogs.net/alternativedotnet/archive/2008/09/02/124869.aspx</link>
            <description>&lt;p&gt;I'm starting to really enjoy what RoR offers out of the box. This framework is really designed around the application lifecycle we all try to reinvent on every project.&lt;/p&gt;
&lt;h1&gt;Rails&lt;/h1&gt;
&lt;p&gt;Rails is the framework for web development over a database. Compare it to asp.net on dotnet. However, Rails is much more than a web UI. Read on...&lt;/p&gt;
&lt;h2&gt;Ease of development&lt;/h2&gt;
&lt;p&gt;When creating any kind of object, extra files are being generated as well, like helper classes, test classes, database migration scripts, fixtures, ... Most of the quotes that follow are command line commands. Since I wanted to know exactly what's happening, I used only the command line, notepad++ and Firefox.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; rails my_test_project&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Generates a complete project structure with MVC, database scripts, environment definitions, test repositories, configuration, ...&lt;/p&gt;
&lt;h2&gt;Management of multiple environments&lt;/h2&gt;
&lt;p&gt;With a freshly generated project, you get three environments: development, test and production. You can add as many as you like. Each environment has its own database, which can each be from a different vendor.&lt;/p&gt;
&lt;h2&gt;MVC&lt;/h2&gt;
&lt;p&gt;Rails supports the MVC pattern out of the box&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; ruby script/generate controller Site index about help&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This command generates:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;A site_controller having index, about and help actions &lt;/li&gt;
    &lt;li&gt;A view for each of these actions &lt;/li&gt;
    &lt;li&gt;A site_helper class &lt;/li&gt;
    &lt;li&gt;A site_controller_test functional test &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The three views are instantly up and running&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; ruby script/generate model User&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;This command generates:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;A user model. Equivalent to what we call an entity &lt;/li&gt;
    &lt;li&gt;A user_test unit test &lt;/li&gt;
    &lt;li&gt;A users test fixture. This is a file where you set up the users you want in the database when running tests &lt;/li&gt;
    &lt;li&gt;A database script for the new entity &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Scaffolding is entirely supported:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&amp;gt; ruby script/generate scaffold Post blog_id:integer title:string body:text&lt;/p&gt;
&lt;p&gt;&amp;gt; rake db:migrate&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The first command will generate the MVC triad necessary to manage posts. The second will generate the database table to persist the actions.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124869"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124869" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/alternativedotnet/aggbug/124869.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michel Grootjans</dc:creator>
            <guid>http://geekswithblogs.net/alternativedotnet/archive/2008/09/02/124869.aspx</guid>
            <pubDate>Tue, 02 Sep 2008 21:37:53 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/alternativedotnet/comments/124869.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/alternativedotnet/archive/2008/09/02/124869.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/alternativedotnet/comments/commentRss/124869.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/alternativedotnet/services/trackbacks/124869.aspx</trackback:ping>
        </item>
        <item>
            <title>Ever tried Ruby on Rails?</title>
            <link>http://geekswithblogs.net/alternativedotnet/archive/2008/08/29/124775.aspx</link>
            <description>&lt;p&gt;I'm taking this step. This technology has been on my radar for quite a while.  Now I'm taking the plunge.&lt;/p&gt;
&lt;p&gt;I've bought this book that looks really promising on the subject.  &lt;strong&gt;&lt;/strong&gt;&lt;a target="_blank" href="http://www.amazon.com/RailsSpace-Building-Networking-Addison-Wesley-Professional/dp/0321480791/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1219959051&amp;amp;sr=8-1"&gt;RailsSpace: Building a Social Networking Website with Ruby on  Rails&lt;/a&gt;. I'm halfway chapter 6 right now, and I'M LOVING IT. I have decided to  make the most out of this experience, so I'm going to build this application  along with the book. I've set up my little &lt;a target="_blank" href="https://grootjansrailsapace.googlecode.com/"&gt;SVN on  Google&lt;/a&gt; where I will keep my evolution up to date.&lt;/p&gt;
&lt;h4&gt;&lt;strong&gt;Chapter 1:&lt;/strong&gt; Introduction.&lt;/h4&gt;
&lt;p&gt;This one's easy. Just a narrative introduction.&lt;/p&gt;
&lt;h4&gt;&lt;strong&gt;Chapter 2:&lt;/strong&gt; Getting started.&lt;/h4&gt;
&lt;p&gt;This chapter explains how to install Ruby, RubyGems and Rails. I also  installed a mySql database since RoR seems to work well with it. It claims to be  databse agnostic (shouldn't that be database &lt;em&gt;polytheistic&lt;/em&gt; ?), so  SqlServer shouldn't be a problem, but I don't want to go too far off the beaten  path of the book. &lt;br /&gt;
All the major platforms are supported in the book, but the  examples are Mac-based. I'm WinXP based, and up until now this hasn't bothered  me a bit.&lt;/p&gt;
&lt;p&gt;Then it moves to the actual creation of a project. This is the first step  that made me feel all warm inside. Go to the console, navigate to whatever  directory (to me that's d:\\projects) and type &lt;font face="Courier"&gt;'rails  the_name_of_the_project_you_want'&lt;/font&gt;. That's it! You now have your whole  project structure set up. Let me run you trough it quickly:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;app  &lt;/li&gt;
    &lt;li&gt;config  &lt;/li&gt;
    &lt;li&gt;db  &lt;/li&gt;
    &lt;li&gt;lib  &lt;/li&gt;
    &lt;li&gt;log  &lt;/li&gt;
    &lt;li&gt;public  &lt;/li&gt;
    &lt;li&gt;script  &lt;/li&gt;
    &lt;li&gt;test  &lt;/li&gt;
    &lt;li&gt;tmp  &lt;/li&gt;
    &lt;li&gt;vendor &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Next I just start the web application by typing &lt;font face="Courier"&gt;'ruby  script/server'&lt;/font&gt;. Bam, I've got a web site running on &lt;a href="http://localhost:3000/"&gt;http://localhost:3000/&lt;/a&gt; (don't click on this  link... you might be disappointed). Of course this is not much, but it's a  start.&lt;/p&gt;
&lt;p&gt;Next I generate my first Controller with a few Views. I type &lt;font face="Courier"&gt;'ruby script/generate controller Site index about help'&lt;/font&gt;.  This creates a controller named &lt;font face="Courier"&gt;Site_controller&lt;/font&gt; and  three views: &lt;font face="Courier"&gt;index&lt;/font&gt;, &lt;font face="Courier"&gt;about&lt;/font&gt;  and &lt;font face="Courier"&gt;help&lt;/font&gt;. That's it, we've basically built three web  pages for our site. They're all using a master &lt;font face="Courier"&gt;layout&lt;/font&gt;,  similar to a master page in asp.net.&lt;/p&gt;
&lt;p&gt;A nice highlight on what you can do in a view:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier"&gt;link_to "Home", :controller =&amp;gt; :site, :action =&amp;gt;  :index&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;As a C# developer, the syntax looks a little alien to me, but I've had worse  ;-) This inserts a link in a view that points to the action (==method) 'index'  of the 'site_controller' class. You can exchange '&lt;font face="Courier"&gt;link_to&lt;/font&gt;' with '&lt;font face="Courier"&gt;link_to_unless_current&lt;/font&gt;' which will do exactly what it  says.&lt;/p&gt;
&lt;h4&gt;Chapter 3: Modeling users&lt;/h4&gt;
&lt;p&gt;In RoR, models seem to be what we understand under Domain Objects in .net.  Before I start modeling, I have to set up a database. TDD, BDD, DDD and other  *DD aficionado's will probably be frowning right now, but bear with me. Magic's  up ahead! In the &lt;font face="Courier"&gt;config&lt;/font&gt; directory, theres a file  called &lt;font face="Courier"&gt;database.yml&lt;/font&gt;. This file holds the connection  definition to all the databases I will be using during my development lifecycle:  development, test, production. I just need to create two of these three  databases: dev and test.&lt;/p&gt;
&lt;p&gt;Next, I type &lt;font face="Courier"&gt;'ruby script/generate model User'&lt;/font&gt;.  This generates a bunch of files. One particularly caught my attention: &lt;font face="Courier"&gt;db/migrate/20080816134931_create_users.rb&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;After adding the fileds I need, the file looks like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier"&gt;class CreateUsers &amp;lt; ActiveRecord::Migration &lt;br /&gt;
  def  self.up &lt;br /&gt;
    create_table :users do |t| &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier"&gt;      t.column :screen_name, :string &lt;br /&gt;
      t.column  :email,       :string &lt;br /&gt;
      t.column :password,    :string &lt;br /&gt;
    end &lt;br /&gt;
   end &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier"&gt;  def self.down &lt;br /&gt;
    drop_table :users &lt;br /&gt;
  end  &lt;br /&gt;
end&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Do you see the magic? This file describes declaratively what needs to be done  to the database to move to version 1 of the app. No SQL statements, just a  declaration of the &lt;em&gt;intent&lt;/em&gt;. At this time, the actual database is still  empty. Let's change that: '&lt;font face="Courier"&gt;rake db:migrate&lt;/font&gt;'. The  development database now contains the right table with the necessary records.  '&lt;font face="Courier"&gt;rake db:migrate VERSION=0&lt;/font&gt;' will reverse the database  to version 0. Further up on the road, you will be able to type '&lt;font face="Courier"&gt;rake db:migrate VERSION=0080816134931&lt;/font&gt;' to revert to the db  version like it is now. Imagine the ease of deployment and rollback of  deployments.&lt;/p&gt;
&lt;h4&gt;The road ahead&lt;/h4&gt;
&lt;p&gt;There's plenty of magic coming up. Chapter 3 isn't completely covered here.  I'll be posting regular updates on this blog to keep you informed on my journey  in this completely new world.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124775"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=124775" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/alternativedotnet/aggbug/124775.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Michel Grootjans</dc:creator>
            <guid>http://geekswithblogs.net/alternativedotnet/archive/2008/08/29/124775.aspx</guid>
            <pubDate>Thu, 28 Aug 2008 22:51:29 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/alternativedotnet/comments/124775.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/alternativedotnet/archive/2008/08/29/124775.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/alternativedotnet/comments/commentRss/124775.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/alternativedotnet/services/trackbacks/124775.aspx</trackback:ping>
        </item>
    </channel>
</rss>