Neo4j-paperclip example

80 views
Skip to first unread message

John Clegg

unread,
Nov 16, 2014, 6:21:46 PM11/16/14
to neo...@googlegroups.com
Hi 

I'm trying to get Neo4j-paperclip working and I'm getting an error in sinatra (Padrino).

I'm getting the following error

No handler found for {"tempfile"=>#<Tempfile:/var/folders/sf/fjy566gx75xc6zwypk7hpj8d5st7rm/T/RackMultipart20141117-9072-w8mddq>, "filename"=>"IMG_7677.JPG", "content_type"=>"image/jpeg", "size"=>400768}


Here is my model file 

class Image
  include Neo4j::ActiveNode
  include Neo4jrb::Paperclip
  id_property :db_id, auto: :uuid
  has_neo4jrb_attached_file :base_image, :url => "/images/:class/:attachment/:id/:style_:filename", :keep_old_files => true,:path => "/Code/public/images/raw/:class/:attachment/:id_partition/:style/:filename"
  validates_attachment_content_type :base_image, content_type: ["image/jpg", "image/jpeg", "image/png", "image/gif","image/webp"]
  property :created_at
  property :updated_at
end

####### Controller


 post :upload_photo, :map => "/photo/", :csrf_protection => false do
    paperclip = {}
    paperclip['tempfile'] = params[:file][:tempfile]
    paperclip['filename'] = params[:file][:filename]
    paperclip['content_type'] = params[:file][:type]
    paperclip['size'] = params[:file][:tempfile].size

      image = Image.new(:base_image => paperclip )
      halt "There were some errors processing your request..." unless image.save
  end


#### view

        <form action="/web/restaurants/photo" method="POST" enctype="multipart/form-data">
            <input type="file" name="file">
            <input type="submit" value="Upload image">
        </form>

Googling shows there is something wrong with the object names. Can anyone share an example of neo4j-paperclip ?

Thanks 

John

Chris Grigg

unread,
Nov 17, 2014, 12:23:04 PM11/17/14
to neo...@googlegroups.com
Hey John. Here's a page where someone describes issues with Padrino and Paperclip. http://midwire.github.io/blog/2014/01/31/padrino/. Looks like adding `gem 'paperclip-rack', require: 'paperclip/rack'` may fix your issue. https://github.com/t-k/paperclip-rack

John Clegg

unread,
Nov 17, 2014, 8:17:48 PM11/17/14
to neo...@googlegroups.com
Hi Chris,

After much yakshaving , I've abandoned Paperclip and gone with Dragonfly. (I tried using Paperclip-rack with and without neo4j-paperclip. I proved too difficult) 

I had to manipulate a method from neo4jrb  to get it work -  active_node/query_methods.rb - function  include?(other). There was a conflict in model definition and include and the " extend Dragonfly::Model" call that needed to run for Dragonfly. 

The error was 
  ERROR -  Neo4j::ActiveNode::QueryMethods::InvalidParameterError - :include? only accepts nodes:
 /Users/john.clegg/.rvm/gems/ruby-2.0.0-p594/gems/neo4j-3.0.3/lib/neo4j/active_node/query_methods.rb:41:in `include?'
/Users/john.clegg/.rvm/gems/ruby-2.0.0-p594/gems/neo4j-3.0.3/lib/neo4j/active_node/query_methods.rb:41:in `include?': :include? only accepts nodes (Neo4j::ActiveNode::QueryMethods::InvalidParameterError)

Now that I have Dragon uploading an image . I'll be able to properly integrate into my code.

Cheers

John

Chris Grigg

unread,
Nov 17, 2014, 8:37:18 PM11/17/14
to neo...@googlegroups.com
We actually removed `include?` entirely from `query_methods.rb` recently, it was part of the release two days ago. Do a `bundle update neo4j` to get up to v3.0.4 and it'll be fixed!

John Clegg

unread,
Nov 17, 2014, 9:47:43 PM11/17/14
to neo...@googlegroups.com
Fantastic - That works like a charm!

Then in order to get dragonfly and neo4jrb working

1) Add Dragonfly to Gemfile

gem 'dragonfly'

2) Add   extend Dragonfly::Model to your class and use dragonfly_accessor as your image variable

class Image
   include Neo4j::ActiveNode
   extend Dragonfly::Model
   dragonfly_accessor :image
end

3) Set up the Dragonfly config as per http://markevans.github.io/dragonfly/configuration/

For me using Padrino / Sinatra it was in the config/boot.rb file.

And it works !
Reply all
Reply to author
Forward
0 new messages