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.
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.
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.
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
modulePaperclipclassCropper < Thumbnaildeftransformation_commandif@attachment.instance.cropping?
crop_command
elsesuperendenddefcrop_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
endendendend
Apologies for the Hungarian notation. Old programmer & bad habits die hard.
I have sort of got it.
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.
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.
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.
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.
Apologies for the Hungarian notation. Old programmer & bad habits die hard.