Class: Fae::UtilitiesController

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

Instance Method Summary collapse

Methods included from NavItems

#nav_items

Instance Method Details

#language_preferenceObject



28
29
30
31
32
33
# File 'app/controllers/fae/utilities_controller.rb', line 28

def language_preference
  if params[:language].present? && (params[:language] == 'all' || Fae.languages.has_key?(params[:language].to_sym))
    current_user.update_column(:language, params[:language])
  end
  render nothing: true
end

#sortObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/fae/utilities_controller.rb', line 14

def sort
  if request.xhr?
    ids = params[params[:object]]
    params[:object].gsub!('fae_', 'fae/')
    klass = params[:object].classify.constantize
    items = klass.find(ids)
    items.each do |item|
      item.position = ids.index(item.id.to_s) + 1
      item.save
    end
  end
  render nothing: true
end

#toggleObject



4
5
6
7
8
9
10
11
12
# File 'app/controllers/fae/utilities_controller.rb', line 4

def toggle
  klass = params[:object].gsub('fae_', 'fae/').classify.constantize
  if can_toggle(klass)
    klass.find(params[:id]).toggle(params[:attr]).save(validate: false)
    render nothing: true
  else
    render nothing: true, status: :unauthorized
  end
end