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
@user.upload_image
end
the model:
def upload_image
if user_image_file && user_image_file != "" then
file = user_image_file
write_attribute(:image_mime_type,
MIME::Types.type_for(file.original_filename).to_s.gsub(''image/'',
''''))
File.open(File.join(IMAGE_FILE_LOCATION,
image_filename(:original)), ''wb'') { |f| f.write(file.read) }
save
end
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---