Class: Cms::ResourceController

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

Instance Method Summary collapse

Methods included from PageHelper

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

Methods included from PathHelper

#attachment_path_for, #cms_connectable_path, #cms_index_path_for, #cms_index_url_for, #cms_new_path_for, #cms_new_url_for, #cms_sortable_column_path, #edit_cms_connectable_path, #engine_for, #link_to_usages, #path_elements_for

Methods included from ErrorHandling

#handle_access_denied, #handle_server_error, #with_format

Instance Method Details

#createObject



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

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



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

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



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

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

#indexObject



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

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

#newObject



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

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

#showObject



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

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

#updateObject



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

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