Class: Cms::ResourceController

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

Instance Method Summary collapse

Methods inherited from BaseController

allow_guests_to

Methods inherited from ApplicationController

#no_browser_caching

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(resource_params)
  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.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(resource_params())
    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