summaryrefslogtreecommitdiff
path: root/app/helpers/application_helper.rb
blob: b74fa27db72c3ba7e5b176e241c831677b76a3d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module ApplicationHelper

  # nicely_joined_with_commata(['1', '2', '3', '4'])
  # = '1, 2, 3 und 4'
  #
	def nicely_joined_with_commata(array_of_things)
		if array_of_things.count == 1
			array_of_things.first.to_s
		else
			if array_of_things.count > 1
        output = array_of_things[0, array_of_things.count - 1].map{|item| item.to_s}.join(', ')
        if I18n.locale == :de
          output += ' und '
        else
        	output += ' and '
        end
        output += array_of_things.last.to_s
      end
    end
	end

  def sortable(column, title)
    link_class = (column.to_s == sort_column.to_s) ? "sort_descending #{sort_descending}" : nil
    desc = (column.to_s == sort_column.to_s) ? !!(!sort_descending && column) : nil
    link_to title, {:sort => column, :desc => desc, :type => @type}, {:class => link_class}
  end

end