Class: SimpleAdmin::AdminController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/simple_admin/admin_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/simple_admin/admin_controller.rb', line 44

def create
  @resource = @interface.constant.new(params.require(@interface.member.to_sym).permit!)
  # respond_with will fail without explicit urls
  respond_to do |format|
    if @resource.save
      format.html { redirect_to send("simple_admin_#{@interface.member}_path", @resource), :notice => "#{@interface.member.titleize} was successfully created." }
      format.json { render :json => @resource, :status => :created, :location => send("simple_admin_#{@interface.member}_path", @resource) }
      format.xml { render :xml => @resource, :status => :created, :location => send("simple_admin_#{@interface.member}_path", @resource) }
    else
      format.html { render :action => "new" }
      format.json { render :json => @resource.errors, :status => :unprocessable_entity }
      format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
    end
  end
end

#dashboardObject



85
86
# File 'app/controllers/simple_admin/admin_controller.rb', line 85

def dashboard
end

#destroyObject



75
76
77
78
79
80
81
82
83
# File 'app/controllers/simple_admin/admin_controller.rb', line 75

def destroy
  @resource.destroy
  # respond_with will fail without explicit urls
  respond_to do |format|
    format.html { redirect_to send("simple_admin_#{@interface.collection}_path") }
    format.json { head :ok }
    format.xml  { head :ok }
  end
end

#editObject



40
41
42
# File 'app/controllers/simple_admin/admin_controller.rb', line 40

def edit
  respond_with(@resource)
end

#indexObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/simple_admin/admin_controller.rb', line 15

def index
  @collection ||= @interface.constant rescue nil

  if @collection
    @collection = @collection.search(clean_search_params(params)).result
    @collection = @collection.order("#{@interface.constant.table_name}.#{$1} #{$2}") if params[:order] && params[:order] =~ /^([\w\_\.]+)_(desc|asc)$/
    @collection = @collection.page(params[:page]).per(params[:per_page] || SimpleAdmin.default_per_page) if params[:format].blank? || params[:format] == 'html'
  end
  respond_to do |format|
    format.csv
    format.html
    format.xml { render :xml => @collection }
    format.json { render :json => @collection }
  end
end

#newObject



35
36
37
38
# File 'app/controllers/simple_admin/admin_controller.rb', line 35

def new
  @resource ||= @interface.constant.new
  respond_with(@resource)
end

#showObject



31
32
33
# File 'app/controllers/simple_admin/admin_controller.rb', line 31

def show
  respond_with(@resource)
end

#updateObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/simple_admin/admin_controller.rb', line 60

def update
  # respond_with will fail without explicit urls
  respond_to do |format|
    if @resource.update_attributes(params.require(@interface.member.to_sym).permit!)
      format.html { redirect_to send("simple_admin_#{@interface.member}_path", @resource), :notice => "#{@interface.member.titleize} was successfully updated." }
      format.json { head :ok }
      format.xml { head :ok }
    else
      format.html { render :action => "edit" }
      format.json { render :json => @resource.errors, :status => :unprocessable_entity }
      format.xml { render :xml => @resource.errors, :status => :unprocessable_entity }
    end
  end
end