Hello, I have a problem with upload file into server, the server machine
have Debian and the application is running with Apache2. My problem is
that I can’t upload a photo in the site (the site is running in the 80
port and I have passenger in the server), and when I run “ruby
script/server” to depurate error and I try to upload file into server, I
can upload file correctly(this is in the 3000 port).
I don’t have idea to solved this problem, I am trying to solve this
problem for 3 weeks. If anyone can help I would appreciate that.
This is my function in the model to upload file
def mount_image
filename = self.image
extension = File.extname(filename.to_s)
if [ ‘.jpg’, ‘.png’, ‘.gif’ ].include?(extension)
path =
“/var/www/apps/playerpress.com/public/users/#{self.id}/user_image/”
FileUtils.mkdir_p(path)
img_file = File.join(path+filename)
if File.exist?(img_file)
File.delete(img_file)
end
File.open(img_file,'wb') do |file| file.write(self.image.read) end
end
end
In the controller I have this
def update
@user = User.find(params[:id])
old_image = @user.image
path_file = @user.path_image.to_s+old_image.to_s
# guardamos el usertype del usuario que se está por modificar
old_usertype = @user.usertype
respond_to do |format|
if @user.update_attributes(params[:user])
if @user.image.to_s ==""
@user.update_attributes({:image => old_image})
else
if old_image != @user.image
if File.exist?(path_file)
File.delete(path_file)
end
@user.mount_image
end
end
end
end
And the view I have this line
PictureClick here to browse<%= f.file_field :image %>