<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>CSCI E-168</title>
	
	<link>http://e168f09.plugh.org</link>
	<description>Building Web-based Software with Ruby and Ruby on Rails</description>
	<lastBuildDate>Sun, 13 Dec 2009 22:20:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/plugh/e168f09" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="plugh/e168f09" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">plugh/e168f09</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Quick live code from Sunday Section</title>
		<link>http://e168f09.plugh.org/2009/12/13/quick-live-code-from-sunday-section/</link>
		<comments>http://e168f09.plugh.org/2009/12/13/quick-live-code-from-sunday-section/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 22:20:00 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=775</guid>
		<description><![CDATA[Attached is the quick and dirty multiple model form from today&#8217;s section.
Click here to download.
]]></description>
			<content:encoded><![CDATA[<p>Attached is the quick and dirty multiple model form from today&#8217;s section.</p>
<p><a href="http://e168f09.plugh.org/wp-content/uploads/2009/12/section.zip">Click here</a> to download.</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/12/13/quick-live-code-from-sunday-section/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New features for Java 7 . . . smells like Ruby</title>
		<link>http://e168f09.plugh.org/2009/11/25/new-features-for-java-7-smells-like-ruby/</link>
		<comments>http://e168f09.plugh.org/2009/11/25/new-features-for-java-7-smells-like-ruby/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 14:39:32 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=755</guid>
		<description><![CDATA[Here&#8217;s a blog post summarizing new features for Java 7:
http://code.joejag.com/2009/new-language-features-in-java-7/
The new features are:

Language support for collections (like Ruby . . . but apparently still no Hash literal &#8212; probably way too late to wedge that in)
Automatic resource management (like Ruby&#8217;s IO objects that yield a reference to a block . . . but looks far [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a blog post summarizing new features for Java 7:</p>
<p><a href="http://code.joejag.com/2009/new-language-features-in-java-7/" target="_blank">http://code.joejag.com/2009/new-language-features-in-java-7/</a></p>
<p>The new features are:</p>
<ul>
<li>Language support for collections (like Ruby . . . but apparently still no Hash literal &#8212; probably way too late to wedge that in)</li>
<li>Automatic resource management (like Ruby&#8217;s IO objects that yield a reference to a block . . . but looks far less general)</li>
<li>New type inference operator</li>
<li>Underscores in numeric literals (1_000_000) (like Ruby)</li>
<li>Strings in switch statements (like Ruby . . . but only for Strings, so no &#8216;case equals&#8217; operator)</li>
<li>binary literals (like Ruby)</li>
<li>Simplified varargs</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/11/25/new-features-for-java-7-smells-like-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple Form / Partial Example</title>
		<link>http://e168f09.plugh.org/2009/11/08/simple-form-partial-example/</link>
		<comments>http://e168f09.plugh.org/2009/11/08/simple-form-partial-example/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 22:29:41 +0000</pubDate>
		<dc:creator>Jonathan</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=648</guid>
		<description><![CDATA[Another completed project from the Sunday section.
This application makes use of the following:

form_for
Partials for DRYness
has_many :through where tables and foreign keys don&#8217;t match
collection_select drop downs
named_scope and default_scope

Click here to download the completed application.
]]></description>
			<content:encoded><![CDATA[<p>Another completed project from the Sunday section.</p>
<p>This application makes use of the following:</p>
<ul>
<li>form_for</li>
<li>Partials for DRYness</li>
<li>has_many :through where tables and foreign keys don&#8217;t match</li>
<li>collection_select drop downs</li>
<li>named_scope and default_scope</li>
</ul>
<p><a href="http://e168f09.plugh.org/wp-content/uploads/2009/11/section.zip">Click here</a> to download the completed application.</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/11/08/simple-form-partial-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A “thank you” to Rails from Django</title>
		<link>http://e168f09.plugh.org/2009/11/06/a-thank-you-to-rails-from-django/</link>
		<comments>http://e168f09.plugh.org/2009/11/06/a-thank-you-to-rails-from-django/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 14:52:43 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=644</guid>
		<description><![CDATA[Interesting post from a Django-ist:
http://jacobian.org/writing/thank-you-rails/
]]></description>
			<content:encoded><![CDATA[<p>Interesting post from a Django-ist:</p>
<p><a href="http://jacobian.org/writing/thank-you-rails/">http://jacobian.org/writing/thank-you-rails/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/11/06/a-thank-you-to-rails-from-django/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nice book chapter on REST</title>
		<link>http://e168f09.plugh.org/2009/11/01/nice-book-chapter-on-rest/</link>
		<comments>http://e168f09.plugh.org/2009/11/01/nice-book-chapter-on-rest/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 15:29:59 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=605</guid>
		<description><![CDATA[I think I&#8217;ve recommended this book before: Eldon Alameda&#8217;s Practical Rails Projects.
It has a sweet chapter on building a RESTful application, and shows very well how the controllers should be &#8220;rescoped&#8221; to work only on data that is appropriate. This &#8220;rescoping&#8221; is part of the requirements for Assignment 4 (requirement #5 about not letting users [...]]]></description>
			<content:encoded><![CDATA[<p>I think I&#8217;ve recommended this book before: Eldon Alameda&#8217;s Practical Rails Projects.</p>
<p>It has a sweet chapter on building a RESTful application, and shows very well how the controllers should be &#8220;rescoped&#8221; to work only on data that is appropriate. This &#8220;rescoping&#8221; is part of the requirements for Assignment 4 (requirement #5 about not letting users edit data &#8220;owned&#8221; by another user).</p>
<p>That chapter is a free download: </p>
<p>http://www.apress.com/book/view/1590597818</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/11/01/nice-book-chapter-on-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Assignment 4 download available</title>
		<link>http://e168f09.plugh.org/2009/10/31/assignment-4-download-available/</link>
		<comments>http://e168f09.plugh.org/2009/10/31/assignment-4-download-available/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 06:37:06 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=596</guid>
		<description><![CDATA[For those of you who burn the midnight oil, as I do . . .
The download for Assignment 4 (and 5) is available on the downloads page. I&#8217;ll send an e-mail tomorrow morning (the Harvard e-mail service is unavailable from 1 AM to 4 AM!!).
]]></description>
			<content:encoded><![CDATA[<p>For those of you who burn the midnight oil, as I do . . .</p>
<p>The download for Assignment 4 (and 5) is available on the downloads page. I&#8217;ll send an e-mail tomorrow morning (the Harvard e-mail service is unavailable from 1 AM to 4 AM!!).</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/10/31/assignment-4-download-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What gets validated?</title>
		<link>http://e168f09.plugh.org/2009/10/26/what-gets-validated/</link>
		<comments>http://e168f09.plugh.org/2009/10/26/what-gets-validated/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 19:45:28 +0000</pubDate>
		<dc:creator>Antony</dc:creator>
				<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=523</guid>
		<description><![CDATA[Say you have a model called Match with attributes wins and losses, both of type integer.  To this model you add validation to ensure these attributes are only integers:

class Match &#60; ActiveRecord::Base
 validates_numericality_of :wins, :only_integer =&#62; true
 validates_numericality_of :losses, :only_integer =&#62; true
end

Then, in script/console:

&#62;&#62; m = Match.new
=&#62; #&#60;Match id: nil, wins: nil, losses: nil, created_at: [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have a model called Match with attributes wins and losses, both of type integer.  To this model you add validation to ensure these attributes are only integers:</p>
<pre class="brush: ruby;">
class Match &lt; ActiveRecord::Base
 validates_numericality_of :wins, :only_integer =&gt; true
 validates_numericality_of :losses, :only_integer =&gt; true
end
</pre>
<p>Then, in script/console:</p>
<pre class="brush: bash;">
&gt;&gt; m = Match.new
=&gt; #&lt;Match id: nil, wins: nil, losses: nil, created_at: nil, updated_at: nil&gt;
&gt;&gt; m.wins = &quot;seven&quot;
=&gt; &quot;seven&quot;
&gt;&gt; m.losses = &quot;five&quot;
=&gt; &quot;five&quot;
&gt;&gt; m
=&gt; #&lt;Match id: nil, wins: 0, losses: 0, created_at: nil, updated_at: nil&gt;
&gt;&gt; m.valid?
=&gt; false
</pre>
</pre>
<p>The strings have been cast as integers, but why does the validation fail?  The answer is that ActiveRecord stores much more information than what shows up as instance attributes.</p>
<pre class="brush: bash;">
&gt;&gt; m.attributes_before_type_cast
=&gt; {&quot;created_at&quot;=&gt;nil, &quot;losses&quot;=&gt;&quot;five&quot;, &quot;updated_at&quot;=&gt;nil, &quot;wins&quot;=&gt;&quot;seven&quot;}
</pre>
</pre>
<p>An indepth look at all of the machinery of ActiveRecord might be a course in itself, but I thought this would provide a taste of the breadth and depth of the ORM.</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/10/26/what-gets-validated/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Migrating existing data</title>
		<link>http://e168f09.plugh.org/2009/10/26/migrating-existing-data/</link>
		<comments>http://e168f09.plugh.org/2009/10/26/migrating-existing-data/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 19:19:10 +0000</pubDate>
		<dc:creator>Antony</dc:creator>
				<category><![CDATA[Announcements]]></category>
		<category><![CDATA[Tips & Tricks]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=519</guid>
		<description><![CDATA[Agile Web Development with Rails, 17.4 and 17.5, covers this subject.
On page 307 of the PDF, Migrating Data with Migrations, the basic scheme you might use is demonstrated.  As another example, suppose I create a users table and model:

$ ./script/generate model users first_name:string last_name:string

The migration looks like this:

class CreateUsers &#60; ActiveRecord::Migration
 def self.up
   [...]]]></description>
			<content:encoded><![CDATA[<p>Agile Web Development with Rails, 17.4 and 17.5, covers this subject.</p>
<p>On page 307 of the PDF, Migrating Data with Migrations, the basic scheme you might use is demonstrated.  As another example, suppose I create a users table and model:</p>
<pre class="brush: bash;">
$ ./script/generate model users first_name:string last_name:string
</pre>
<p>The migration looks like this:</p>
<pre class="brush: ruby;">
class CreateUsers &lt; ActiveRecord::Migration
 def self.up
   create_table :users do |t|
     t.string :first_name
     t.string :last_name

     t.timestamps
   end
 end

 def self.down
   drop_table :users
 end
end
</pre>
<p>After adding a number of users, it becomes clear that a full_name attribute would be very useful:</p>
<pre class="brush: bash;">
$ ./script/generate migration AddFullNameToUser full_name:string
</pre>
<p>This new migrations looks like this:</p>
<pre class="brush: ruby;">
class AddFullNameToUser &lt; ActiveRecord::Migration
  def self.up
    add_column :users, :full_name, :string
  end

  def self.down
    remove_column :users, :full_name
  end
end
</pre>
<p>Before running it, I add the line to update the users:</p>
<pre class="brush: ruby;">
class AddFullNameToUser &lt; ActiveRecord::Migration
  def self.up
    add_column :users, :full_name, :string
    User.find(:all).each do |u|
      u.full_name = u.first_name + ' ' + u.last_name
      u.save!
    end
  end

  def self.down
    remove_column :users, :full_name
  end
end
</pre>
<p>An important note here:  I did not use update_all because string concatenation is not portable between database engines (|| for Oracle, postgres and sqlite3, + for SQL Server and Sybase,  concat for MySQL, etc).</p>
<p>As John demonstrated in his migrations 3 example, depending on what you are trying to accomplish, the down method may not be data preserving.</p>
<p>Beyond the above and similar data manipulation, section 17.5 covers ways to execute fragments of native SQL or arbitrary SQL.  Using this functionality is beyond the scope of this course and of course has the significant downside of being much less portable.</p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/10/26/migrating-existing-data/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>gem of the week: cheat</title>
		<link>http://e168f09.plugh.org/2009/10/13/gem-of-the-week-cheat/</link>
		<comments>http://e168f09.plugh.org/2009/10/13/gem-of-the-week-cheat/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 20:21:11 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gems]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=433</guid>
		<description><![CDATA[A couple of weeks ago I mentioned the &#8220;cheat&#8221; gem which has a plethora of useful quick docs on various topics such as regular expressions. I breezed through the install &#8212; and fix for Ruby 1.9.1 &#8212; here it is, for the record:

gem install cheat
# NOTE: If you're on Linux or OS/X and have a [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I mentioned the &#8220;cheat&#8221; gem which has a plethora of useful quick docs on various topics such as regular expressions. I breezed through the install &#8212; and fix for Ruby 1.9.1 &#8212; here it is, for the record:</p>
<pre class="brush: ruby;">
gem install cheat
# NOTE: If you're on Linux or OS/X and have a standard install (rather than using the ruby_switch.sh script, you want to do sudo gem install cheat)
</pre>
<p>If you run it under 1.9.x, you should get an error like so:</p>
<pre class="brush: ruby;">
cheat regexp
/Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb:150:in `cache_dir': uninitialized constant Cheat::PLATFORM (NameError)
	from /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb:16:in `sheets'
	from /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/bin/cheat:4:in `&lt;top (required)&gt;'
	from /Users/jnorman/.gem/ruby/1.9.1/bin/cheat:19:in `load'
	from /Users/jnorman/.gem/ruby/1.9.1/bin/cheat:19:in `&lt;main&gt;'
</pre>
<p>What you want to do is edit the file producing the error (in my case, from the exception trace, /Users/jnorman/.gem/ruby/1.9.1/gems/cheat-1.2.1/lib/cheat.rb). Go to the line, and change the constant PLATFORM to RUBY_PLATFORM. Save the file.</p>
<p>And voila!</p>
<pre class="brush: ruby;">
chelsea:~ jnorman$ cheat regexp
regexp:
  A regexp's form is written /pattern/modifiers where &quot;pattern&quot; is the regular
# much deleted
</pre>
<p>For help,</p>
<pre class="brush: ruby;">
cheat cheat
</pre>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/10/13/gem-of-the-week-cheat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keeping projects small, code brevity</title>
		<link>http://e168f09.plugh.org/2009/10/13/keeping-projects-small-code-brevity/</link>
		<comments>http://e168f09.plugh.org/2009/10/13/keeping-projects-small-code-brevity/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 13:59:41 +0000</pubDate>
		<dc:creator>john</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://e168f09.plugh.org/?p=429</guid>
		<description><![CDATA[I know a number of you are interested in how Ruby and Rails seems to favor smaller projects, code brevity, and a general attitude of representational efficiency.
You might be interested in this new post by Ola Bini who discusses the claim that if a project is very big, you need all of the helps from [...]]]></description>
			<content:encoded><![CDATA[<p>I know a number of you are interested in how Ruby and Rails seems to favor smaller projects, code brevity, and a general attitude of representational efficiency.</p>
<p>You might be interested in this new post by Ola Bini who discusses the claim that if a project is very big, you need all of the helps from a statically-typed language (such as Java).</p>
<p><a href="http://olabini.com/blog/2009/10/plan-to-write-big-software-and-you-have-already-lost/">http://olabini.com/blog/2009/10/plan-to-write-big-software-and-you-have-already-lost/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://e168f09.plugh.org/2009/10/13/keeping-projects-small-code-brevity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

