RailsCasts Pro episodes are now free!

Learn more or hide this

Sean Bamforth's Profile

GitHub User: seanbamforth

Site: http://theguru.co.uk

Comments by Sean Bamforth

Avatar

I have sort of got it.

faqs_for_user = params[:faq].map{|x| x.to_i} & current_user.faq_id_list
faqs_for_user.each_with_index do |id, index|

The faq_id_list returns a list of id's that are allowed to be sorted. The procedure relies on the fact that the array intersection function returns items in the same order as the first parameter. (gulp)

If anyone has anything better here, would be good to see it.

Avatar

Anyone done anything with this & update_all where the items being sorted have a user_id parent. As it is, a Post with a random set of Faq's could resort regardless of who the parent user_id is.

Avatar

I set the position to Time.now.to_i as a default. You don't need to know a max position or reference the database to place it at the bottom of the list.

Avatar

I had all sorts of trouble getting the cropper changes to work. Firstly, you'll need to restart your Rails server every time you change the Paperclip changes.

Secondly, I couldn't really get the cropping code to work without putting quotes around the resize and cropping amounts. Because I always crop to a certain size, I completely replaced the array used in the transformation command.

ruby
module Paperclip
  class Cropper < Thumbnail
    def transformation_command
      if @attachment.instance.cropping?
        crop_command
      else
        super
      end
    end
    
    def crop_command
      target = @attachment.instance
      if target.cropping?
        sTransform = "#{target.crop_w.to_i}x#{target.crop_h.to_i}+#{target.crop_x.to_i}+#{target.crop_y.to_i}"
        sTransform = ('"'+sTransform+'"')
        trans = []
        trans = trans << "-crop" << sTransform
        trans << "-resize" << "\"800x200\""
        trans 
      end
    end
  end
end

Apologies for the Hungarian notation. Old programmer & bad habits die hard.