title: getting encoding error cannot convert ascii-8bit to utf-8bit
body: <p>I am using this code for uploading the profile image of a user</p>
  
  <pre><code>if params[:user][:image].present?
    uploaded_io = params[:user][:image]
    name = "image_" &lt;&lt; @user.username &lt;&lt; uploaded_io.original_filename
    File.open(Rails.root.join('public', 'images','profile',name ), 'w') do |file|
      file.write(uploaded_io.read)
    end
  end  
  </code></pre>
  
  <p>but its giving this error when i run it <code>cannot convert ascii-8bit to utf-8bit</code>
  so what i did was i changed my default encoding in <code>application.rb</code> file like this <code>config.encoding = "ascii-8bit"</code> from <code>config.encoding = "utf-8"</code>. and it started working fine.</p>
  
  <p>But the problem is now I am sending a mail to the user for successful registeration from simple rails mailer and now before sending the mail its giving me this error <code>cannot convert utf-8bit to ascii-8bit</code>.</p>
  
  <p>Now I am totally struck only one of them works at one time. I have tried a lot of suggested solutions to <code>enforce_encoding on strings</code> but none of them seems to work. Any help would be appreciated. Thanks.</p>