Class: Admin::SitesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/admin/sites_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#fresh_when, #redirect_back_or_default, #redirect_referrer_or_default, #render_403, #render_404, #render_optional_error_file, #require_user, #set_active_menu, #set_locale, #set_seo_meta, #store_location, #unread_notify_count

Instance Method Details

#createObject


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

def create
  @site = Site.new(params[:site].permit!)

  respond_to do |format|
    if @site.save
      format.html { redirect_to(admin_sites_path, notice: 'Site 创建成功。') }
      format.json
    else
      format.html { render action: 'new' }
      format.json
    end
  end
end

#destroyObject


66
67
68
69
70
71
72
73
74
# File 'app/controllers/admin/sites_controller.rb', line 66

def destroy
  @site = Site.unscoped.find(params[:id])
  @site.destroy

  respond_to do |format|
    format.html { redirect_to(admin_sites_path, notice: "#{@site.name} 删除成功。") }
    format.json
  end
end

#editObject


34
35
36
# File 'app/controllers/admin/sites_controller.rb', line 34

def edit
  @site = Site.unscoped.find(params[:id])
end

#indexObject


3
4
5
6
7
8
9
10
11
12
13
14
# File 'app/controllers/admin/sites_controller.rb', line 3

def index
  @sites = Site.unscoped.recent.includes(:user, :site_node)
  if params[:q]
    @sites = @sites.where('name LIKE ?',"%#{params[:q]}%")
  end
  @sites = @sites.paginate(page: params[:page], per_page: 20)

  respond_to do |format|
    format.html # index.html.erb
    format.json
  end
end

#newObject


25
26
27
28
29
30
31
32
# File 'app/controllers/admin/sites_controller.rb', line 25

def new
  @site = Site.new

  respond_to do |format|
    format.html # new.html.erb
    format.json
  end
end

#showObject


16
17
18
19
20
21
22
23
# File 'app/controllers/admin/sites_controller.rb', line 16

def show
  @site = Site.unscoped.find(params[:id])

  respond_to do |format|
    format.html # show.html.erb
    format.json
  end
end

#undestroyObject


76
77
78
79
80
# File 'app/controllers/admin/sites_controller.rb', line 76

def undestroy
  @site = Site.unscoped.find(params[:id])
  @site.update_attribute(:deleted_at, nil)
  redirect_to(admin_sites_path, notice: "#{@site.name} 已恢复。")
end

#updateObject


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/admin/sites_controller.rb', line 52

def update
  @site = Site.unscoped.find(params[:id])

  respond_to do |format|
    if @site.update_attributes(params[:site].permit!)
      format.html { redirect_to(admin_sites_path, notice: 'Site 更新成功。') }
      format.json
    else
      format.html { render action: 'edit' }
      format.json
    end
  end
end