Image upload in ruby with sinatra and datamapper and Carrierwave?

I want to upload a single image with Carrierwave, the thing is, it is uploading the file and saving it into the directory uploads, in this folder it creates another folder called tmp, and in the tmp folder it creates another folder which includes the image. The thing is it doesn't seem to stop it is uploading and uploading and uploading all the time even if the image is fully uploaded into that folder and I can open this image already with feh(or anyother image viewer).

This is what my controller looks like.

get "/new" do
    protect!

    erb :new
end

post "/new" do
    protect!

    @user = User.get(session[:user_id])
    image = @user.image.new(
        :description => params[:description],
        :image => params[:image]
    )

    # image.save

    "NEVER REACHED!"

end

(The text "NEVER REACHED!" won't be displayed at all and I don't know why...)

This is my model:

class ImageUploader < CarrierWave::Uploader::Base
    def extensions_white_list
        %w(jpg jpeg gif png)
    end

    storage :file
end

class Image
    include DataMapper::Resource

    property :id, Serial
    property :description, Text

    property :image, String, :auto_validation => false
    mount_uploader :image, ImageUploader
end

class User
    include DataMapper::Resource

    property :id, Serial

    has n, :post
end

So as already mentioned the Text "NEVER REACHED" is never reached. Any Ideas why?

Besides I always get the warning:

Defining property for an uploader is deprecated at /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'

And I do not know why...

UPDATE: It is somehow working now as long as I do not uncomment image.save in the main controller, but I actually need to uncomment this, any Ideas how to fix this?

Answers


Remove property :image line in your Image model as:

class Image
    include DataMapper::Resource

    property :id, Serial
    property :description, Text

    mount_uploader :image, ImageUploader
end

mount_uploader by itself defines the :image as String type.

Try to run your application after this and let me know if the condition remains the same. :)


Need Your Help

How to customize the windows shell to display files from a remote source and allow custom drawing?

windows winapi shell customization windows-explorer

Is it possible, (via some shell extension or similar) to customize the Windows shell (explorer.exe) to accomplish the following?