title: Error, Ruby on Rails: Encoding::UndefinedConversionError in CoursesController#attachment "\xFF" from ASCII-8BIT to UTF-8
body: <p>I'd like to make a simple file uploader using tag_form on Rails 3.2.8.<br>
  But when I try to submit a image file, I get an error saying
  <br>
  <br>
  <strong>Error Message (when I try to submit a image file)</strong></p>
  
  <blockquote>
    <p>Encoding::UndefinedConversionError in CoursesController#attachment<br>
    "\xFF" from ASCII-8BIT to UTF-8</p>
  </blockquote>
  
  <p>I'd appreciate it if you help me with this problem.<br>
  Here's my codes.</p>
  
  <p><br>
  <strong>app/view/show.html.erb</strong></p>
  
  <pre><code>&lt;%= form_tag(attachment_course_path, :action=&gt;'attachment', :multipart =&gt; true) do %&gt;
  &lt;div class="field"&gt;
    &lt;%= label_tag :file %&gt;
    &lt;%= file_field_tag :file %&gt;
  &lt;/div&gt;
  &lt;div class="actions"&gt;
    &lt;%= submit_tag 'Submit' %&gt;
  &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><br>
  <strong>app/controller/courses_controller.rb</strong></p>
  
  <pre><code>def attachment
    t = Time.now.strftime("%Y%m%d%H%M%S")
    uploaded_io = params[:file]
    File.open(Rails.root.join('public', 'upload', uploaded_io.original_filename), 'w') do |file|
      file.write(uploaded_io.read)
    end
  end
  </code></pre>
  
  <p><br>
  <strong>config/routes.rb</strong></p>
  
  <pre><code>resources :courses, :only =&gt; [ :show ] do
    member do
      post :attachment
    end
  end
  </code></pre>