Class: WeixinPam::DiymenusController

Inherits:
ApplicationController show all
Defined in:
app/controllers/weixin_pam/diymenus_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /diymenus



24
25
26
27
28
29
30
31
32
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 24

def create
  @diymenu = @public_account.diymenus.new(diymenu_params)

  if @diymenu.save
    redirect_to (@public_account), notice: '菜单创建成功.'
  else
    render :new
  end
end

#destroyObject

DELETE /diymenus/1



43
44
45
46
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 43

def destroy
  @diymenu.destroy
  redirect_to (@public_account), notice: '删除菜单成功.'
end

#downloadObject



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

def download
  @public_account.download_menu!
  flash[:notice] = '下载成功.'
  render js: "Turbolinks.visit('#{(@public_account)}');"
rescue ApiError::FailedResult => ex
  render json: { action: :download, error: "#{ex.message} - #{ex.result.cn_msg}" }
end

#editObject

GET /diymenus/1/edit



20
21
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 20

def edit
end

#indexObject

GET /diymenus



9
10
11
12
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 9

def index
  @page_name = 'diymenus_index'
  @diymenus = @public_account.diymenus
end

#newObject

GET /diymenus/new



15
16
17
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 15

def new
  @diymenu = @public_account.diymenus.new
end

#sortObject



48
49
50
51
52
53
54
55
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 48

def sort
  state = JSON.parse(params[:state])
  enabled_menus, disabled_menus = state

  save_sorted_menus enabled_menus, true
  save_sorted_menus disabled_menus, false
  render json: { action: :sort }
end

#updateObject

PATCH/PUT /diymenus/1



35
36
37
38
39
40
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 35

def update
  if @diymenu.update(diymenu_params)
    flash[:notice] = '修改成功.'
  end
  render :edit
end

#uploadObject



57
58
59
60
61
62
63
64
# File 'app/controllers/weixin_pam/diymenus_controller.rb', line 57

def upload
  result = @public_account.upload_menu
  render json: {
    action: :upload,
    ok: result.ok?,
    msg: result.cn_msg
  }
end