Class: Activa::PagesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/activa/pages_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_ability

Instance Method Details

#createObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/activa/pages_controller.rb', line 29

def create
  @page = Activa::Page.new(params[:page])

  # Publish page immediately
  if params[:commit].present?
    if @page.publish
      flash.notice = I18n.t 'controllers.pages.create.published_notice'
      smart_redirect_to(@page) and return
    end
  # Save page as a draft and continue editing
  elsif params[:save_as_draft].present?
    if @page.save_as_draft
      flash.notice = I18n.t 'controllers.pages.create.draft_notice'
      redirect_to(activa.edit_page_path(@page)) and return
    end
  end
  
  respond_with(@page)
end

#destroyObject



65
66
67
68
69
70
71
72
# File 'app/controllers/activa/pages_controller.rb', line 65

def destroy
  if @page.destroy
    flash.notice = I18n.t 'controllers.pages.destroy.notice'
    redirect_to(activa.pages_path) and return
  end

  respond_with(@page) and return
end

#editObject



25
26
27
# File 'app/controllers/activa/pages_controller.rb', line 25

def edit
  
end

#indexObject



10
11
12
# File 'app/controllers/activa/pages_controller.rb', line 10

def index
  @pages = Activa::Page.roots
end

#newObject



18
19
20
21
22
23
# File 'app/controllers/activa/pages_controller.rb', line 18

def new
  @page = Activa::Page.new
  @page.parent_id = params[:parent_id].to_i

  respond_with(@page)
end

#positionObject



78
79
80
81
82
83
84
# File 'app/controllers/activa/pages_controller.rb', line 78

def position
  render :json => Activa::Page.move(
    params[:first_node_id],
    params[:second_node_id],
    params[:nesting]
  )
end

#showObject



14
15
16
# File 'app/controllers/activa/pages_controller.rb', line 14

def show

end

#slugObject



74
75
76
# File 'app/controllers/activa/pages_controller.rb', line 74

def slug
  render :json => { :slug => params[:title].to_s.to_url }
end

#updateObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/activa/pages_controller.rb', line 49

def update
  if params[:commit].present?
    if @page.update_attributes(params[:page])#@page.publish#(params[:page])
      flash.notice = I18n.t 'controllers.pages.create.published_notice'
      smart_redirect_to(@page) and return
    end
  elsif params[:save_as_draft].present?

    if @page.update_as_draft(params[:page])
      redirect_to(activa.edit_page_path(@page)) and return
    end
  end

  respond_with(@page)
end