Class: BlocksController

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

Instance Method Summary collapse

Instance Method Details

#createObject


6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/blocks_controller.rb', line 6

def create
  begin
    block_service.block(Person.find_by!(id: block_params[:person_id]))
  rescue ActiveRecord::RecordNotUnique
  end

  respond_to do |format|
    format.json { head :no_content }
    format.any { redirect_back fallback_location: root_path }
  end
end

#destroyObject


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/blocks_controller.rb', line 18

def destroy
  notice = nil
  begin
    block_service.remove_block(current_user.blocks.find_by!(id: params[:id]))
    notice = {notice: t("blocks.destroy.success")}
  rescue ActiveRecord::RecordNotFound
    notice = {error: t("blocks.destroy.failure")}
  end

  respond_to do |format|
    format.json { head :no_content }
    format.any { redirect_back fallback_location: privacy_settings_path, flash: notice }
  end
end