jquery - Jcrop error: undefined method 'sub' -
rails 4.0.10: i've been following jcrop tutorial: (http://railscasts.com/episodes/182-cropping-images), , i've gotten far submitting cropped image. when press submit button, error:
nomethoderror in thingscontroller#update undefined method `sub' ["-auto-orient", "-resize", "\"500x500\""]:array
i saw question same error, fixed changing super.sub(/ -crop...
in lib/paperclip_processor/cropper "super.first.sub(/ -c...
, returned same exact error in case. has else run issue jcrop?
lib/paperclip_processors/cropper (i put asterisks around line highlighted on error page)
module paperclip class cropper < thumbnail def transformation_command if crop_command ***crop_command + super.sub(/ -crop \s+/, '')*** else super end end def crop_command target = @attachment.instance if target.cropping? " -crop '#{target.crop_w}x#{target.crop_h}+#{target.crop_x}+#{target.crop_y}' " end end end end
views/things/crop.html.erb
<% content_for(:head) %> <%= stylesheet_link_tag "jquery.jcrop" %> <%= javascript_include_tag "jquery.jcrop.min" %> <script type="text/javascript" charset="utf-8"> ready = $(function() { $("#cropbox").jcrop({ onchange: update_crop, onselect: update_crop, setselect: [0, 0, 500, 500], aspectratio: 1 }); }); function update_crop(coords) { $("#crop_x").val(coords.x); $("#crop_y").val(coords.y); $("#crop_w").val(coords.w); $("#crop_h").val(coords.h); } $(document).ready(ready); $(document).on('page:load', ready); </script> <% end %> <%= image_tag @thing.avatar.url(:large), :id => "cropbox" %> <%= form_for @thing |f| %> <% attribute in [:crop_x, :crop_y, :crop_w, :crop_h] %> <%= f.text_field attribute, :id => attribute %> <% end %> <p><%= f.submit "crop" %></p> <% end %>
models/thing.rb
class thing < activerecord::base # ... has_attached_file :avatar, :styles => { :large => "500x500", :medium => "300x300>", :thumb => "50x50!" }, :processors => [:cropper] validates_attachment_content_type :avatar, :content_type => /\aimage\/.*\z/ attr_accessor :crop_x, :crop_y, :crop_w, :crop_h after_update :reprocess_avatar, :if => :cropping? def cropping? !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank? end private def reprocess_avatar avatar.reprocess! end end
Comments
Post a Comment