Forum: Ruby on Rails upload an image

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ishara G. (Guest)
on 2008-11-05 15:03
(Received via mailing list)
can anyone give me the code for upload an image,,i try
in various ways such as acts_as_attatchment plugin but
it wasn't im in a big trouble,,,plz give me another
solution to this
Thorsten M. (Guest)
on 2008-11-05 15:20
(Received via mailing list)
the view:

  <% form_for(@user, :url => (@edition ? user_path() :
user_path), :method => :put, :html => {:multipart => true}) do |f| %>
    <%= f.file_field(:user_image_file) %><br />
    <%= submit_tag('Save') %>
  <% end %>

in the controller:

    if params[:user][:user_image_file] then

the model:

  def upload_image
    if user_image_file && user_image_file != "" then
      file = user_image_file
MIME::Types.type_for(file.original_filename).to_s.gsub('image/', '')),
image_filename(:original)), 'wb') { |f| f.write( }

This topic is locked and can not be replied to.