RailsCasts Pro episodes are now free!

Learn more or hide this

Nick Berveiler's Profile

GitHub User: nberveiler

Comments by Nick Berveiler

Avatar

When incorporating this code within my app, my list was not sorting until I added jquery-ui to my require list in the application.js manifest. Perhaps that is the same issue you are having?

Avatar

Converting from

bootstrap_and_overrides.css.less
@import "reset.less";

to

bootstrap_and_overrides.css.less
@import "twitter/bootstrap/reset";

solved my problem.

Avatar

Using the source code for this episode: store-after-less, I'm getting a Less::ParseError that 'reset.less' wasn't found. I've tried googling this issue and have not found a solution yet. I don't know if this is an issue with the less gem or with the twitter-bootstrap-rails gem.

Avatar

I was unable to get the crop working using RMagick, so I investigated what would be the equivalent using MiniMagick.

Based on this discussion on stackoverflow, I was able to come up with this working solution. This method would be saved in the User model and there is no longer a crop method within the AvatarUploader CarrierWave object.

There is one minor issue with this code, which is that the large version of the image becomes the master copy of that image. If you do not care about keeping the high resolution version of an uploaded image, this issue will not matter to you.

ruby
class User < ActiveRecord::Base
  mount_uploader :image, ImageUploader
  
  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  after_update :crop_image

  def crop_image
    if crop_x.present?
      mini_magick = MiniMagick::Image.open(self.image.large.path)
      crop_params = "#{crop_w}x#{crop_h}+#{crop_x}+#{crop_y}"
      mini_magick.crop(crop_params)
      mini_magick.write(self.image.path)
      image.recreate_versions!
    end
  end
end