ruby on rails - How can I make Paperclip process files from a server directory? -


I want to run a paperclip on all files in a directory on the server. In fact, I would like to permit my webserver to FTP some files, then I can run all the files (can resize images, update database, etc.) to run fine work manually.

How can I do this?

I'm not sure if I understood your question - did you run the rack work away from Saying or importing images?

In the latter case there is an answer.

First you need some models and maybe some other data, something like this:

  class pictures & lt; ActiveRecord :: Base has_attached_file: image ,: styles = & gt; {: Thumb = & gt; "100x100 & gt;" ,: big => "500x500" } End  

You can create simple rack assignments in your Lib / Work folder (you should name the file with .rake extension)

  namespace : Import "import all images from SOURCE_DIR folder" function: images = & gt; : Do not receive all images from the given environment folder.Dr.glob (file. (Niv ["SOURCE_DIR"], "*") do | File_path | # Create a new model for each photo and open it db (file_path). F | Pict = Picture.new (: name = & gt; File.basename (file_path) ,: image = & gt; f) One side effect of saving is that the paperclip conversion will be #pict.save! End # Transfer to another processed image or remove it. This # is required because there is a danger of "double import" # FileUtils.mv (file_path, "....") #FileUtils.rm (file_path) end end  

then you have a console You can call manual rack work providing the SOURCE_DIR parameter which will be the folder on the server (this can be a real folder or remote remote).

  rake import: images SOURCE_DIR = ~ / My_images / If you are planning to run it automatically, then I would like to give you the schedule for scheduling gem Would like to be consulted.  

Updates: To keep things simple I / or / imported

deliberately dropped exception handling


Comments