Class: Admin::PagesController

Inherits:
ForestController
  • Object
show all
Defined in:
app/controllers/admin/pages_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/admin/pages_controller.rb', line 39

def create
  @page = Page.new
  authorize @page

  respond_to do |format|
    if @page.update(page_params)
      format.html { redirect_to edit_admin_page_path(@page), notice: 'Page was successfully created.' }
      format.json { render :show, status: :created, location: @page }
    else
      format.html { render :new }
      format.json { render json: @page.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject



68
69
70
71
72
73
74
75
# File 'app/controllers/admin/pages_controller.rb', line 68

def destroy
  authorize @page
  @page.destroy
  respond_to do |format|
    format.html { redirect_to admin_pages_url, notice: 'Page was successfully destroyed.' }
    format.json { head :no_content }
  end
end

#editObject



35
36
37
# File 'app/controllers/admin/pages_controller.rb', line 35

def edit
  authorize @page
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/admin/pages_controller.rb', line 9

def index
  if request.format.json?
    @pages = apply_scopes(Page).by_title.where.not(id: params[:current_record]).page(params[:page])
  else
    # TODO: fuzzy searching doesn't work properly with page hierarchy
    @parent_pages = apply_scopes(Page.includes(:immediate_children)).parent_pages.page(params[:page])
    @pages = apply_scopes(Page).by_title.page params[:page]
  end

  authorize @pages
  respond_to :html, :json
end

#newObject

def show

unless @page
  raise ActionController::RoutingError.new('Not Found')
end
authorize @page
redirect_to edit_admin_page_path(@page)

end



30
31
32
33
# File 'app/controllers/admin/pages_controller.rb', line 30

def new
  @page = Page.new
  authorize @page
end

#updateObject



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/controllers/admin/pages_controller.rb', line 54

def update
  authorize @page

  respond_to do |format|
    if @page.update(page_params)
      format.html { redirect_to edit_admin_page_path(@page), notice: 'Page was successfully updated.' }
      format.json { render :show, status: :ok, location: @page }
    else
      format.html { render :edit }
      format.json { render json: @page.errors, status: :unprocessable_entity }
    end
  end
end