Class: Decidim::Pages::CopyPage
- Inherits:
-
Command
- Object
- Command
- Decidim::Pages::CopyPage
- Defined in:
- app/commands/decidim/pages/copy_page.rb
Overview
Command that gets called whenever a component’s page has to be duplicated. It is need a context with the old component that is going to be duplicated on the new one
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(context) ⇒ CopyPage
constructor
A new instance of CopyPage.
Constructor Details
#initialize(context) ⇒ CopyPage
Returns a new instance of CopyPage.
9 10 11 |
# File 'app/commands/decidim/pages/copy_page.rb', line 9 def initialize(context) @context = context end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'app/commands/decidim/pages/copy_page.rb', line 13 def call Decidim::Pages::Page.transaction do pages = Decidim::Pages::Page.where(component: @context[:old_component]) pages.each do |page| Decidim::Pages::Page.create!(component: @context[:new_component], body: page.body) end end broadcast(:ok) rescue ActiveRecord::RecordInvalid broadcast(:invalid) end |