snipt

Ctrl+h for KB shortcuts

Ruby

reprocess paperclip thumbnails

1
2
3
# Given Photo has_attached_file
# `image` is the has_attached_file name
Photo.find(:all).each { |a| a.image.reprocess!; a.save }
https://snipt.net/embed/a30a5725ec8ae21faa8a55952ed34b7c/
/raw/a30a5725ec8ae21faa8a55952ed34b7c/
a30a5725ec8ae21faa8a55952ed34b7c
rb
Ruby
4
2019-08-22T16:19:19
True
False
False
/api/public/snipt/13340/
reprocess-paperclip-thumbnails
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1"># Given Photo has_attached_file</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># `image` is the has_attached_file name</span> </span><span id="L-3"><a name="L-3"></a><span class="no">Photo</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="ss">:all</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">a</span><span class="o">|</span> <span class="n">a</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">reprocess!</span><span class="p">;</span> <span class="n">a</span><span class="o">.</span><span class="n">save</span> <span class="p">}</span> </span></pre></div> </td></tr></table>
paperclip, rails, regenerate, reprocess, ruby, thumbnails