Class: Cms::ResourceController

Inherits:
BaseController show all
Defined in:
app/controllers/cms/resource_controller.rb

Overview

This is meant to be extended by other controller Provides basic Restful CRUD

Instance Method Summary collapse

Methods included from PageHelper

#able_to?, #cms_toolbar, #container, #container_has_block?, #current_page, #page_title, #render_breadcrumbs, #render_portlet

Methods included from PathHelper

#cms_connectable_path, #cms_index_path_for, #cms_index_url_for, #cms_new_path_for, #cms_new_url_for, #edit_cms_connectable_path

Methods included from ErrorHandling

#handle_access_denied, #handle_server_error, included

Instance Method Details

#createObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/cms/resource_controller.rb', line 13

def create
  @object = build_object(params[variable_name])
  if @object.save
    flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was created"
    redirect_to after_create_url
  else
    instance_variable_set("@#{variable_name}", @object)
    if (params[:on_fail_action])
      render :action => params[:on_fail_action]
    else
      render :action => 'new'
    end
  end
end

#destroyObject



51
52
53
54
55
56
57
# File 'app/controllers/cms/resource_controller.rb', line 51

def destroy
  @object = resource.find(params[:id])
  if @object.destroy
    flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was deleted"
  end
  redirect_to index_url
end

#editObject



32
33
34
# File 'app/controllers/cms/resource_controller.rb', line 32

def edit
  instance_variable_set("@#{variable_name}", resource.find(params[:id]))
end

#indexObject



5
6
7
# File 'app/controllers/cms/resource_controller.rb', line 5

def index
  instance_variable_set("@#{variable_name.pluralize}", resource.all(:order => order_by_column))
end

#newObject



9
10
11
# File 'app/controllers/cms/resource_controller.rb', line 9

def new
  instance_variable_set("@#{variable_name}", build_object)
end

#showObject



28
29
30
# File 'app/controllers/cms/resource_controller.rb', line 28

def show
  instance_variable_set("@#{variable_name}", resource.find(params[:id]))
end

#updateObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/cms/resource_controller.rb', line 36

def update
  @object = resource.find(params[:id])
  if @object.update_attributes(params[variable_name])
    flash[:notice] = "#{resource_name.singularize.titleize} '#{object_name}' was updated"
    redirect_to after_update_url
  else
    instance_variable_set("@#{variable_name}", @object)
    if (params[:on_fail_action])
      render :action => params[:on_fail_action]
    else
      render :action => 'edit'
    end
  end
end