Class: ArticleUnitsController
Instance Method Summary
collapse
current
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#create ⇒ Object
33
34
35
|
# File 'app/controllers/article_units_controller.rb', line 33
def create
@article_unit = ArticleUnit.create(unit: params[:unit])
end
|
#destroy ⇒ Object
37
38
39
40
|
# File 'app/controllers/article_units_controller.rb', line 37
def destroy
@article_unit = ArticleUnit.find(params[:id])
@article_unit.destroy
end
|
#index ⇒ Object
5
|
# File 'app/controllers/article_units_controller.rb', line 5
def index; end
|
#search ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'app/controllers/article_units_controller.rb', line 7
def search
@query = article_unit_params[:q].blank? ? nil : article_unit_params[:q].downcase
existing_article_units = ArticleUnit.all.to_a
@article_units = @available_units
.to_h do |key, value|
[key, value.merge({ code: key, record: existing_article_units.find do |existing_unit|
existing_unit.unit == key
end })]
end
unless @query.nil?
@article_units = @article_units.select do |_key, value|
(value[:name].downcase.include?(@query) || value[:symbol]&.downcase&.include?(@query)) &&
(params[:only_recommended] == '0' || !value[:untranslated])
end
end
@article_units = @article_units
.sort { |a, b| sort_by_unit_name(@query, a, b) }
.map { |_key, value| value }
@article_units = @article_units.take(100) unless @query.nil?
@article_units = @article_units.reject { |unit| unit[:record].nil? } if @query.nil?
end
|