Regenerate posts asynchronously using a delayed job. Regenerating a post can be slow because it involves downloading the original file, regenerating the thumbnails, and redistributing the new thumbnails back to the image servers. It's better to run this in the background, especially if a user is trying to regenerate posts in bulk. The downside is there's no notification to the user when the regeneration is complete. You have to check the modactions log to see when it's finished.
12 lines
372 B
Ruby
12 lines
372 B
Ruby
class PostRegenerationsController < ApplicationController
|
|
respond_to :xml, :json, :html
|
|
|
|
def create
|
|
@post = authorize Post.find(params[:post_id]), :regenerate?
|
|
@post.regenerate_later!(params[:category], CurrentUser.user)
|
|
flash[:notice] = "Post regeneration scheduled, press Ctrl+F5 in a few seconds to refresh the image"
|
|
|
|
respond_with(@post)
|
|
end
|
|
end
|