Class: Admin::ChannelsController

Inherits:
BaseController show all
Defined in:
app/controllers/admin/channels_controller.rb

Constant Summary

Constants inherited from BaseController

BaseController::INTERNAL_SERVER_ERROR_MESSAGE

Instance Method Summary collapse

Methods inherited from BaseController

#destroy_session, #identity_cache_memoization, #sign_in_page, #user_developer_session

Methods included from LogrageCustomLogger

#append_info_to_payload

Methods included from AdminHelper

#dynamic_pricings_formatter, #link_to_admin_reservations_path_by_id, #link_to_admin_restaurants_path_by_id, #link_to_log, #optional_locales, #optional_locales_with_labels, #staff_signed_in?

Methods included from UpdateLocaleConcern

#setup_locale

Methods inherited from ApplicationController

#after_sign_in_path_for, #after_sign_out_path_for, #default_url_options, #identity_cache_memoization, #render_not_found, #routing_error, search_params_key=

Methods included from ControllerHelpers

#check_boolean_param, #get_banners, #inventory_params, #reservation_params

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/controllers/admin/channels_controller.rb', line 24

def create
  @channel = Channel.new(channel_params)

  if @channel.save
    redirect_to admin_channels_path, notice: 'Channel was successfully created.'
  else
    render action: 'new'
  end
rescue ActiveRecord::RecordNotUnique
  flash.now[:alert] = 'Vendor has already been taken.'
  render action: 'new'
end

#destroyObject

don't delete a channel every booking will be has nil channel data if you delete a channel



67
68
69
70
71
72
73
74
75
76
# File 'app/controllers/admin/channels_controller.rb', line 67

def destroy
  # @channel = Channel.find(params[:id])
  # msg = if @channel.destroy
  #         { notice: 'Channel deleted successfully' }
  #       else
  #         { alert: 'Failed delete channel' }
  #       end
  msg = { alert: 'you can not delete a channel, please contact Saiqul' }
  redirect_to admin_channels_url, msg
end

#editObject



20
21
22
# File 'app/controllers/admin/channels_controller.rb', line 20

def edit
  @channel = Channel.find(params[:id])
end

#indexObject



6
7
8
9
10
# File 'app/controllers/admin/channels_controller.rb', line 6

def index
  @channels = Channel.all.sort_by(&:channel_id)
  etag = CityHash.hash32([self.class.to_s, Channel.maximum(:updated_at)])
  return unless stale?(etag: etag)
end

#newObject



16
17
18
# File 'app/controllers/admin/channels_controller.rb', line 16

def new
  @channel = Channel.new
end

#showObject



12
13
14
# File 'app/controllers/admin/channels_controller.rb', line 12

def show
  @channel = Channel.find(params[:id])
end

#updateObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/admin/channels_controller.rb', line 37

def update
  @channel = Channel.find(params[:id])

  respond_to do |format|
    format.html do
      if @channel.update_attributes(channel_params)
        redirect_to admin_channel_path(@channel), notice: 'Channel was successfully updated.'
      else
        render action: 'edit'
      end
    end
    format.json do
      tag = params.require(:tag_name)
      if params['add'].to_i == 1
        @channel.tag_list.add tag
      else
        @channel.tag_list.remove tag
      end

      @channel.save
      render json: @channel.tags.to_json
    end
  end
rescue ActiveRecord::RecordNotUnique
  flash.now[:alert] = 'Vendor has already been taken.'
  render action: 'edit'
end