-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now use Module#prepend for decorators
- Loading branch information
1 parent
1fe5866
commit 53a3a47
Showing
4 changed files
with
36 additions
and
47 deletions.
There are no files selected for viewing
18 changes: 8 additions & 10 deletions
18
app/decorators/controllers/refinery/admin/blogposts_controller_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
if defined?(Refinery::Blog) | ||
Refinery::Blog::Admin::PostsController.prepend( | ||
Module.new do | ||
def permitted_post_params | ||
params[:post][:images_attributes]={} if params[:post][:images_attributes].nil? | ||
super << [images_attributes: [:id, :caption, :image_page_id]] | ||
end | ||
end | ||
) | ||
end | ||
module RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams | ||
def permitted_post_params | ||
params[:post][:images_attributes]={} if params[:post][:images_attributes].nil? | ||
super << [images_attributes: [:id, :caption, :image_page_id]] | ||
end | ||
end | ||
|
||
Refinery::Blog::Admin::PostsController.prepend(RefineryPageImagesAddRefineryBlogAdminPostsCrontrollerParams) rescue NameError |
18 changes: 8 additions & 10 deletions
18
app/decorators/controllers/refinery/admin/pages_controller_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,8 @@ | ||
if defined?(Refinery::Page) | ||
Refinery::Admin::PagesController.prepend( | ||
Module.new do | ||
def permitted_page_params | ||
params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? | ||
super << [images_attributes: [:id, :caption, :image_page_id]] | ||
end | ||
end | ||
) | ||
end | ||
module RefineryPageImagesAddRefineryAdminPagesControllerParams | ||
def permitted_page_params | ||
params[:page][:images_attributes]={} if params[:page][:images_attributes].nil? | ||
super << [images_attributes: [:id, :caption, :image_page_id]] | ||
end | ||
end | ||
|
||
Refinery::Admin::PagesController.prepend(RefineryPageImagesAddRefineryAdminPagesControllerParams) rescue NameError |
23 changes: 20 additions & 3 deletions
23
app/decorators/models/refinery/page_images_page_decorator.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,20 @@ | ||
if defined?(Refinery::Page) | ||
Refinery::Page.include RefineryPageImages::AddImagesWithCaptionsConcern | ||
end | ||
require 'ostruct' | ||
|
||
module RefineryPageImagesAddImagesWithCaptions | ||
def self.prepended(base) | ||
base.attr_accessor :images_with_captions | ||
end | ||
|
||
def images_with_captions | ||
@images_with_captions = image_pages.map do |ref| | ||
OpenStruct.new( | ||
{ | ||
image: Refinery::Image.find(ref.image_id), | ||
caption: ref.caption || '' | ||
} | ||
) | ||
end | ||
end | ||
end | ||
|
||
Refinery::Page.prepend(RefineryPageImagesAddImagesWithCaptions) rescue NameError |
24 changes: 0 additions & 24 deletions
24
app/models/concerns/refinery_page_images/add_images_with_captions_concern.rb
This file was deleted.
Oops, something went wrong.