Skip to content

Commit

Permalink
Add a decorator for BlogPosts
Browse files Browse the repository at this point in the history
  • Loading branch information
anitagraham authored and parndt committed Nov 26, 2014
1 parent e96aa29 commit 475ced5
Showing 1 changed file with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
if defined?(Refinery::Blog)
Refinery::Blog::Admin::PostsController.class_eval do

# work around an issue with stack level too deep, due to an issue with decorators.
if self.instance_methods.exclude?(:post_params_with_page_image_params)
# We need to add :images_attributes to post_params as it is ignored by strong parameters. (See #100)
def post_params_with_page_image_params

# Get the :images_attributes hash from params
page_image_params = params.require(:post).permit(images_attributes: [:id, :caption])

# If there is no :images_attributes hash use a blank hash (so it removes deleted images)
page_image_params = {images_attributes:{}} if page_image_params[:images_attributes].nil?

# Add the :images_attributes hash to the default post_params hash
post_params_without_page_image_params.merge(page_image_params)

end

# Swap out the default post_params method with our new one
alias_method_chain :post_params, :page_image_params
end
end
end

0 comments on commit 475ced5

Please sign in to comment.