title: Updating database records in Rails
body: <p>I'm new to RoR and I'm now confusing about updating data to databases.
  And I studied RoR just recently, if the question is unclear please let me know.</p>
  
  <p>Assume I created a table "book", with 3 columns: "name", "price", and "author".</p>
  
  <p>When implementing action update in rails, I'll do the following:</p>
  
  <pre><code>def update
    @book = Book.find(params[:id])
    if @book.update({'name': 'Ruby tutorial'})
      redirect_to @book
    else
      render 'edit'
    end
  end
  </code></pre>
  
  <p>This will update the record in database by </p>
  
  <pre><code>if @article.update({'name': 'Ruby tutorial'})
  </code></pre>
  
  <p>In order to test some failure cases, I modified the database column "name" to "nane" on purpose,
  I thought the statement <strong>if @article.update</strong> will fail due to the wrong table field name and the code will go to else block.
  Because I thought the statement is for checking whether rails saves the record into the database successfully.</p>
  
  <p>However, my code throws exception because of the wrong field name instead of going to the else block.</p>
  
  <p>I got confused about this behavior, what kinds of situation will cause 
  <strong>if @article.update(params)</strong> fail and go to the else block?</p>
  
  <p>Is <strong>if @article.update(params)</strong> for just validating form data? i.e, checking whether the hash key sent from the form is correct, as for database side(field name or database connection error) , is not the business of this statement so it will throw exception.</p>
  
  <p>Thanks a lot.</p>