Picture upload

Since you're new to RoR, why not use a plugin like Paperclip? It does
exactly what you're trying to do and much more...should save you a lot
of time.

http://www.thoughtbot.com/projects/paperclip

http://railscasts.com/episodes/134-paperclip

Lee Smith wrote:

Since you're new to RoR, why not use a plugin like Paperclip? It does
exactly what you're trying to do and much more...should save you a lot
of time.

http://www.thoughtbot.com/projects/paperclip

http://railscasts.com/episodes/134-paperclip

Thanks for your answer.

Ok now I have a problem with paperclip. Is it possible that it doesn't
work under windows vista? I installed the plugin and tried the example
from the paperclip page. There are entries in the db but with null
values in the image related columns and the pictures are not in the
puplic directory.

I'm getting crazy!

Here is what I've done:

challenge.rb

class Challenge < ActiveRecord::Base
  belongs_to :user
  has_attached_file :thumbnail, :styles => {:thumb => '100x100>'}

end

new.html.erb

<h1>Post new Challenge</h1>
    <%form_tag :action => 'create', :multipart => true do %>
      <p>Challenge Title: </p>
      <%= text_field 'challenge', 'title'%> <br/>
      <p>Description: </p>
      <%= text_field 'challenge', 'description'%><br/>
      <p>Challenge Thumbnail: </p>
      <%= file_field 'challenge', :thumbnail%>
      <%= submit_tag 'Create' %>
    <%end%>

challenges_controller.rb

def create
    @challenge = Challenge.create params[:challenge]

    if !@challenge.valid?
      flash.now[:error] = 'Bitte füllen sie alle Felder aus!'
      render :action => :new
   else if !@challenge.save
        flash.now[:error] = 'Es trat ein Fehler beim speichern auf!'
        render :action => :new
      else
        redirect_to :action => 'list'
      end
    end

  end

Do you have something like ImageMagick installed? I don't use and
haven't used windows for a while but here is an article that might
help you out...

http://thewebfellas.com/blog/2008/11/2/goodbye-attachment_fu-hello-paperclip

From the docs:

# * +url+: The full URL of where the attachment is publically accessible. This can just

# as easily point to a directory served directly through Apache as it can to an action

# that can control permissions. You can specify the full domain and path, but usually

# just an absolute path is sufficient. The leading slash *must* be included manually for

# absolute paths. The default value is

# "/system/:attachment/:id/:style/:filename". See

# Paperclip::Attachment#interpolate for more information on variable interpolaton.

# :url => "/:class/:attachment/:id/:style_:filename"

# :url => "[http://some.other.host/stuff/:class/:id_:extension](http://some.other.host/stuff/:class/:id_:extension)"

# * +default_url+: The URL that will be returned if there is no attachment assigned.

# This field is interpolated just as the url is. The default value is

# "/:attachment/:style/missing.png"

# has_attached_file :avatar, :default_url => "/images/default_:style_avatar.png"

# User.new.avatar_url(:small) # => "/images/default_small_avatar.png"