Class: PagesController

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

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#is_current_user?

Instance Method Details

- (Object) create

POST /pages POST /pages.xml



92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/pages_controller.rb', line 92

def create
  @page = Page.new(params[:page])
  authorize! :create, Page
  
  respond_to do |format|
    if @page.save
      format.html { redirect_to(@page, :notice => t(:page_successfully_created)) }
      format.xml  { render :xml => @page, :status => :created, :location => @page }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
    end
  end
end

- (Object) create_new_article

POST /pages/create_new_article



108
109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/pages_controller.rb', line 108

def create_new_article
  authorize! :create, Page
  @template = Page.templates.find(params[:page][:template_id])
  @page = Page.new(@template.attributes)
  @page.is_template = false
  @page.template_id=@template.id
  @page.page_components = []
  @template.page_components.each do |component|
    @page.page_components.build( component.attributes )
  end
end

- (Object) delete_cover_picture

GET /pages/:id/delete_cover_picture



158
159
160
161
162
163
164
165
166
167
# File 'app/controllers/pages_controller.rb', line 158

def delete_cover_picture
  @page = Page.find(params[:id])
  authorize! :edit, @page
  @page.cover_picture.destroy
  @page.save
  respond_to do |format|
    format.html { render :nothing => true }
    format.js
  end
end

- (Object) destroy

DELETE /pages/1 DELETE /pages/1.xml



147
148
149
150
151
152
153
154
155
# File 'app/controllers/pages_controller.rb', line 147

def destroy
  @page = Page.find(params[:id])
  authorize! :destroy, @page
  @page.destroy
  respond_to do |format|
    format.html { redirect_to(pages_url) }
    format.xml  { head :ok }
  end
end

- (Object) edit

GET /pages/1/edit



83
84
85
86
87
88
# File 'app/controllers/pages_controller.rb', line 83

def edit
  # Workarround for :fields_for which will ignore default_scope of components
  @page = scoped_pages.find(params[:id])
  authorize! :edit, @page
  @page.page_components.sort! {|a,b| a.position <=> b.position }
end

- (Object) index

GET /pages GET /pages.xml



15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/pages_controller.rb', line 15

def index
  @pages = scoped_pages.order([:menu_order,:asc],[:created_at, :desc]).all.paginate(
    :page => params[:page],
    :per_page => APPLICATION_CONFIG[:pages_per_page] || 5
  )

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @pages }
  end
end

- (Object) new

GET /pages/new GET /pages/new.xml



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

def new
  @page = Page.new
  authorize! :create, @page
  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @page }
  end
end

- (Object) new_article

GET /pages/new_article Presents a list of page-templates. The submit-button will lead to :post /pages/create_new_article



77
78
79
80
# File 'app/controllers/pages_controller.rb', line 77

def new_article
  authorize! :create, Page
  @templates = Page.templates
end

- (Object) permalinked

GET /p/titel_of_the_page



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

def permalinked
  permalink = params[:permalink].url_to_txt.escape_regex
  unless params[:permalink][-1] == '$'
    @page = scoped_pages.where(:title => /^#{permalink}$/i).first
  else
    @page = scoped_pages.where(:title => /^#{permalink.chomp('\$')}(.*)$/i).first
  end
  render :show if @page
  unless @page
    redirect_to pages_path, :alert =>  t(:page_not_found) + " (#{permalink})"
  end
end

- (Object) show

GET /pages/1 GET /pages/1.xml



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

def show
  begin
    @page = scoped_pages.find(params[:id])
  rescue
    redirect_to pages_path, :alert => t(:document_not_found)
    return
  end
  authorize! :show, @page
  params[:comment] ||= {
    :name => user_signed_in? ? current_user.name : t(:anonymous),
    :email=> user_signed_in? ? current_user. : '',
    :comment => ""
  }
  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @page }
  end
end

- (Object) sort_components

GET /pages/sort_components POST /pages/sort_components



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'app/controllers/pages_controller.rb', line 176

def sort_components
  @page = Page.find(params[:id])
  unless params[:component]
    respond_to do |format|
      format.html
      format.js
    end
  else
    params[:component].each_with_index do |component,idx|
      c = @page.page_components.find(component)
      c.position = (idx+1)*10
    end
    @page.save
    render :nothing => true
  end
end

- (Object) templates

GET /pages/templates



170
171
172
# File 'app/controllers/pages_controller.rb', line 170

def templates
  @pages = Page.templates
end

- (Object) update

PUT /pages/1 PUT /pages/1.xml



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'app/controllers/pages_controller.rb', line 122

def update
  @page = Page.find(params[:id])
  authorize! :update, @page
  respond_to do |format|
    if @page.update_attributes(params[:page])
      @page.attachments.each { |att| att.save }
      if @page.is_draft && draft_mode == false
        change_draft_mode(true) 
        notice = t(:page_successfully_updated_and_switched_to_draft_mode)
      else
        notice = t(:page_successfully_updated)
      end
      format.html {
         redirect_to(@page, :notice => notice)
      }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @page.errors, :status => :unprocessable_entity }
    end
  end
end