Class: Maglev::Editor::PagesController

Inherits:
BaseController show all
Includes:
Pagy::Backend
Defined in:
app/controllers/maglev/editor/pages_controller.rb

Instance Method Summary collapse

Methods included from ResourceIdConcern

#resource_id

Instance Method Details

#createObject



28
29
30
31
32
33
34
35
36
# File 'app/controllers/maglev/editor/pages_controller.rb', line 28

def create
  @page = maglev_services.create_page.call(attributes: page_params)
  if @page.persisted?
    redirect_to editor_real_root_path(maglev_editing_route_context(page: @page)), status: :see_other
  else
    flash.now[:alert] = flash_t(:error)
    render :new, status: :unprocessable_content
  end
end

#destroyObject



49
50
51
52
53
# File 'app/controllers/maglev/editor/pages_controller.rb', line 49

def destroy
  @page.destroy!
  redirect_to editor_pages_path(**query_params, **maglev_editing_route_context(page: maglev_home_page)),
              notice: flash_t(:success), status: :see_other
end

#editObject



22
23
24
25
26
# File 'app/controllers/maglev/editor/pages_controller.rb', line 22

def edit
  # we need to store the active tab in the flash
  # because we can't pass the anchor to the redirect
  @active_tab = flash[:active_tab]
end

#indexObject



13
14
15
16
# File 'app/controllers/maglev/editor/pages_controller.rb', line 13

def index
  @pages = fetch_pages
  @pagy, @pages = pagy(@pages, limit: per_page, page_param: 'offset') if pagination_enabled?
end

#newObject



18
19
20
# File 'app/controllers/maglev/editor/pages_controller.rb', line 18

def new
  @page = maglev_page_resources.build
end

#updateObject



38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/maglev/editor/pages_controller.rb', line 38

def update
  if @page.update(page_params)
    flash[:active_tab] = params[:active_tab]
    redirect_to edit_editor_page_path(@page, **query_params, **maglev_editing_route_context),
                notice: flash_t(:success), status: :see_other
  else
    flash.now[:alert] = flash_t(:error)
    render :edit, status: :unprocessable_content
  end
end