<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 class BooksController &lt; ApplicationController
-  before_filter :get_book, :only =&gt; [:show, :edit, :update, :destroy]
-  before_filter :get_authors, :only =&gt; [:new, :edit, :create]
+  before_filter :get_book, :only =&gt; %w|show edit update destroy|
+  before_filter :get_authors, :only =&gt; %w|new edit create|
+  before_filter :fetch_author_from_params, :only =&gt; %w|create update|
   
   # GET /books
   def index
@@ -9,6 +10,7 @@ class BooksController &lt; ApplicationController
 
   # GET /books/1
   def show
+    # @book populated via the before_filter
   end
 
   # GET /books/new
@@ -18,25 +20,25 @@ class BooksController &lt; ApplicationController
 
   # GET /books/1/edit
   def edit
+    # @book populated via the before_filter
   end
 
   # POST /books
   def create
-    @book = Book.new(params[:book])
-    author = Author.find_by_name(params[:author])
-    if (!author)
-      flash[:notice] = &quot;I don't know the author '#{params[:author]}'&quot;
-      render :action =&gt; &quot;new&quot;
-    else
-      @book.author = author
-      @book.save!
+    @book = Book.new(params[:book])    
+    @book.author = @author
+      
+    if (@book.save)
       flash[:notice] = 'Book was successfully created.'
       redirect_to(@book)
+    else
+      render :action =&gt; &quot;new&quot;
     end
   end
 
   # PUT /books/1
   def update
+    params[:book].merge!({&quot;author&quot; =&gt; @author})
     if @book.update_attributes(params[:book])
       flash[:notice] = 'Book was successfully updated.'
       redirect_to(@book)
@@ -59,5 +61,13 @@ private
   
   def get_authors
     @authors = Author.find(:all)
+    if (!@author)
+      flash[:notice] = &quot;I don't know the author '#{params[:author]}'&quot;
+      render :action =&gt; &quot;new&quot; &amp;&amp; return
+    end
+  end
+  
+  def fetch_author_from_params
+    @author = Author.find_by_name(params[:author])
   end
 end</diff>
      <filename>app/controllers/books_controller.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,3 +1,6 @@
 class Book &lt; ActiveRecord::Base
   belongs_to :author
+  
+  validates_uniqueness_of :title
+  validates_length_of :title, :within =&gt; 5..120
 end</diff>
      <filename>app/models/book.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,5 +1,5 @@
+&lt;%= error_messages_for(:book) %&gt;
 &lt;% form_for(@book) do |f| %&gt;
-  &lt;%= f.error_messages %&gt;
   &lt;p&gt;
     &lt;%= f.label :title %&gt;&lt;br /&gt;
     &lt;%= f.text_field :title %&gt;
@@ -7,7 +7,7 @@
 
   &lt;p&gt;
     &lt;%= label_tag &quot;author&quot; %&gt;&lt;br /&gt;
-    &lt;%= text_field_tag &quot;author&quot;, (@book.author &amp;&amp; book.author.name), :size =&gt; 30, :autocomplete =&gt; &quot;off&quot; %&gt;
+    &lt;%= text_field_tag &quot;author&quot;, (@book.author &amp;&amp; @book.author.name), :size =&gt; 30, :autocomplete =&gt; &quot;off&quot; %&gt;
   &lt;/p&gt;
 
   &lt;p&gt;
@@ -20,6 +20,6 @@
   $(&quot;#author&quot;).autocomplete({
     list: &lt;%= @authors.map(&amp;:name).to_json %&gt;,
     timeout: 100,
-    match: function(typed) { return this.match(new RegExp(typed, &quot;i&quot;)); }
+    match: function(typed) { return this.match(new RegExp(&quot;^&quot; + typed, &quot;i&quot;)); }
   })
 &lt;/script&gt;
\ No newline at end of file</diff>
      <filename>app/views/books/_form.html.erb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>978975ca0c1346edde672542b717cb0ee63a2511</id>
    </parent>
  </parents>
  <author>
    <name>Erik Kastner</name>
    <email>kastner@gmail.com</email>
  </author>
  <url>http://github.com/kastner/jquery_demo/commit/ee56bc8cb9506cc26d6f4494c70edbba332c92d5</url>
  <id>ee56bc8cb9506cc26d6f4494c70edbba332c92d5</id>
  <committed-date>2008-08-21T07:23:48-07:00</committed-date>
  <authored-date>2008-08-21T07:23:48-07:00</authored-date>
  <message>Updating files to show editing, and before_filters</message>
  <tree>efd2ebb379c6d9f702da09364b4f484d4773a0e3</tree>
  <committer>
    <name>Erik Kastner</name>
    <email>kastner@gmail.com</email>
  </committer>
</commit>
