Uploading a file from the browser This allows users to upload an file from the browser into my Rails app using the paperclip gem. Once the file is uploaded it gets saved into the filesystem. When the user then goes in and the "show" method or the "edit" method is evoked the image is shown to the user. This is fine for image files but for .csv and .txt files I don't want to show the preview in the browser. This code is clunky and I know there is a better way to do this.

&lt;% if @user.image? %&gt;
&lt;%=filetype = @user.image.url %&gt;&lt;br/&gt;
&lt;%if filetype.include? ".jpeg" %&gt;
    &lt;b&gt;isJpeg&lt;/b&gt;
    &lt;%= image_tag @user.image.url %&gt; &lt;br /&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt; 
&lt;%if filetype.include? ".gif" %&gt;
    &lt;b&gt;isGif&lt;/b&gt;
    &lt;%= image_tag @user.image.url %&gt; &lt;br /&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;
&lt;%if filetype.include? ".png" %&gt;
    &lt;b&gt;isPNG&lt;/b&gt;
    &lt;%= image_tag @user.image.url %&gt; &lt;br /&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;
&lt;%if filetype.include? ".jpg" %&gt;
    &lt;b&gt;isJPG&lt;/b&gt;
    &lt;%= image_tag @user.image.url %&gt; &lt;br /&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;
&lt;%if filetype.include? ".csv" %&gt;
    &lt;b&gt;isCSV&lt;/b&gt;
    &lt;p&gt;Your file was a csv file and has no preview&lt;/p&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;

&lt;%= image_tag @user.image.url %&gt; &lt;br /&gt;
&lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;
tokland is right (on both counts), you should push all that logic into a helper. You can also add a bit of OpenStruct into the mix to make the helper nicer:

# in app/helpers/application_helper.rb or another helper
def user_image_info(user)
    info = OpenStruct.new(:has_image? =&gt; false)
    return info if(!user.image?)

    # There might be better ways to do this but I don't know paperclip.
    u = user.image.url
    %w[jpeg gif png jpg csv].find do |ext|
        # A small abuse of `find` but reasonable in this case.
        info.is = "is#{ext.upcase}" if(u.include?(".#{ext}"))
    end
    if(info.is == 'isCSV')
        info.preview_link = '&lt;p&gt;Your file was a csv file and has no preview&lt;/p&gt;'.html_safe
    else
        info.preview_link = (image_tag(user.image.url) + '&lt;br&gt;').html_safe
    end
    info
end


Then in your ERB, you could do something like this:

&lt;% info = user_image_info(@user) %&gt;
&lt;% if info.has_image? %&gt;
    &lt;b&gt;&lt;%= info.is %&gt;&lt;/b&gt;
    &lt;%= info.preview_link %&gt;
    &lt;%= link_to @user.image.url, @user.image.url  %&gt;
&lt;% end %&gt;