Class: Dhatu::BranchesController

Inherits:
ResourceController show all
Defined in:
app/controllers/dhatu/branches_controller.rb

Instance Method Summary collapse

Methods inherited from ResourceController

#configure_filter_param_mapping, #get_category_filters

Instance Method Details

#make_mainObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/controllers/dhatu/branches_controller.rb', line 6

def make_main
  @branch = @r_object = Dhatu::Branch.find_by_id(params[:id])
  if @branch
    @r_object.update_attribute(:main_branch, true)
    if @r_object.errors.blank?
      set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @r_object.main_branch))
    else
      set_notification(false, I18n.t('status.error'), @r_object.errors.full_messages.join("<br>"))
    end
  else
    set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
  end
  render_row
end

#remove_mainObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/dhatu/branches_controller.rb', line 21

def remove_main
  @branch = @r_object = Dhatu::Branch.find_by_id(params[:id])
  if @branch
    @r_object.update_attribute(:main_branch, false)
    if @r_object.errors.blank?
      set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @r_object.main_branch))
    else
      set_notification(false, I18n.t('status.error'), @r_object.errors.full_messages.join("<br>"))
    end
  else
    set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
  end
  render_row
end