Class: AppyantraAdmin::AssetsController

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

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_breadcrumb, #asset_display_name, #current_breadcrumb, #get_object_name, #set_objects

Instance Method Details

#createObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 22

def create
  asset_object_name = get_object_name @asset_class
  @asset_object = @asset_class.new(params[asset_object_name.to_sym])

  respond_to do |format|
    if @asset_object.save
      format.html do |format|
        flash[:notice] = "#{@asset_name} was successfully created."
        redirect_to "/appyantra_admin/assets/#{@asset_name}/#{@asset_object.id}/show"
      end
    else
      # TODO handle errors
      # format.html { render action: "new" }
    end
  end
end

#destroyObject



54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 54

def destroy
  @asset_object = @asset_class.find(params[:id])
  @asset_object.destroy

  respond_to do |format|
    format.html do |format|
      flash[:notice] = "#{@asset_name} was successfully deleted."
      redirect_to "/appyantra_admin/assets/#{@asset_name}"
    end
  end
end

#displayObject



74
75
76
77
78
79
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 74

def display
  @asset_object = @asset_class.find(params[:id])
  respond_to do |format|
    format.js
  end
end

#editObject



66
67
68
69
70
71
72
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 66

def edit
  asset_id = params[:id]
  @asset_object = @asset_class.find(asset_id)
  add_breadcrumb(["#{asset_display_name @asset_object}", "/appyantra_admin/assets/#{@asset_name}/#{asset_id}/show"])
  @page_title = 'Edit'
  current_breadcrumb @page_title
end

#newObject



16
17
18
19
20
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 16

def new
  @page_title = 'New'
  current_breadcrumb @page_title
  @asset_object = @asset_class.new
end

#showObject



9
10
11
12
13
14
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 9

def show
  @page_title = @asset_name.pluralize
  current_breadcrumb @page_title
  @asset_objects = @asset_class.all
  @asset_object = @asset_class.find(params[:id]) if params[:id]
end

#updateObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/appyantra_admin/assets_controller.rb', line 39

def update
  @asset_object = @asset_class.find(params[:id])
  asset_object_name = @asset_class.table_name.singularize
  respond_to do |format|
    if @asset_object.update_attributes(params[asset_object_name.to_sym])
      format.html do |format|
        flash[:notice] = "#{@asset_name} was successfully updated."
        redirect_to "/appyantra_admin/assets/#{@asset_name}/#{@asset_object.id}/show"
      end
    else
      # TODO handle errors
    end
  end
end