Module ApplicationHelper
In: app/helpers/application_helper.rb

Methods added to this helper will be available to all templates in the application.

Methods

Public Instance methods

[Source]

     # File app/helpers/application_helper.rb, line 107
107:   def analytics
108:     render(:partial => 'shared/analytics') if Constants::Config::GOOGLE_ANALYTICS
109:   end

[Source]

    # File app/helpers/application_helper.rb, line 15
15:   def attribution(item)
16:     (item.attribution && !item.attribution.empty?) ? item.attribution : t('items.anonymous')
17:   end

[Source]

    # File app/helpers/application_helper.rb, line 73
73:   def country_codes
74:     Constants::Countries::CODES
75:   end

[Source]

    # File app/helpers/application_helper.rb, line 69
69:   def error(page, message, delay = Constants::Config::FLASH_DELAY)
70:     page << "Message.error('#{escape_javascript(message)}', #{delay});"
71:   end

[Source]

   # File app/helpers/application_helper.rb, line 3
3:   def fast_link(text, link, html_options='')
4:    %(<a href="#{ActionController::Base.relative_url_root}/#{link}" hmtl_options>#{text}</a>)
5:   end

[Source]

     # File app/helpers/application_helper.rb, line 111
111:   def field_options
112:     { :maxlength => Constants::VARCHAR, :size => 35 }
113:   end

[Source]

     # File app/helpers/application_helper.rb, line 115
115:   def flag_form_tag(suffix = '', &blk)
116:     if @prompt
117:       remote_form_for(:flag, :url => { :action => :flag, :question_id => @question && @question.id }, :condition => "Item.validFlag('#{suffix}')") { |f| blk.call(f) }
118:     else
119:       form_for(:flag, :url => { :action => :flag, :question_id => @question && @question.id }) { |f| blk.call(f) }
120:     end
121:   end

[Source]

    # File app/helpers/application_helper.rb, line 27
27:   def flag_link(obj, downcase = false)
28:     label = t('flag.h')
29:     label.downcase! if downcase
30:     link_to_function label, "$('#flag_#{obj.class == Item ? 'item' : 'comment'}_#{obj.id}').toggle()"
31:   end

[Source]

     # File app/helpers/application_helper.rb, line 123
123:   def google_control_script
124:     if PRODUCTION && I18n.locale == 'en'
125:       "        <script>\n        function utmx_section(){}function utmx(){}\n        (function(){var k='2654905852',d=document,l=d.location,c=d.cookie;function f(n){\n        if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return c.substring(i+n.\n        length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;\n        d.write('<sc'+'ript src=\"'+\n        'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'\n        +'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='\n        +new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+\n        '\" type=\"text/javascript\" charset=\"utf-8\"></sc'+'ript>')})();\n        </script>\n"
126:     end
127:   end

[Source]

     # File app/helpers/application_helper.rb, line 159
159:   def google_optimize(label, text)
160:     PRODUCTION && I18n.locale == 'en' ? "<script>utmx_section(\"#{label}\")</script>#{text}</noscript>" : text
161:   end

[Source]

     # File app/helpers/application_helper.rb, line 142
142:   def google_tracking_script
143:     if PRODUCTION && I18n.locale == 'en'
144:       "        <script type=\"text/javascript\">\n        if(typeof(_gat)!='object')document.write('<sc'+'ript src=\"http'+\n        (document.location.protocol=='https:'?'s://ssl':'://www')+\n        '.google-analytics.com/ga.js\"></sc'+'ript>')</script>\n        <script type=\"text/javascript\">\n        try {\n        var pageTracker=_gat._getTracker(\"UA-8796271-1\");\n        pageTracker._trackPageview(\"/2654905852/test\");\n        }catch(err){}</script>\n"
145:     end
146:   end

[Source]

    # File app/helpers/application_helper.rb, line 89
89:   def groups_for_select(method = 'id', &blk)
90:     Question.all.map { |q| [sanitize(q.groups.first.for_locale(I18n.locale), :tags => []), (blk.nil? ? q.send(method) : yield(q)) ] }
91:   end

[Source]

     # File app/helpers/application_helper.rb, line 93
 93:   def highlightable(item)
 94:     onmouseover = "$$('.item_#{item.id}').each(function(s) { s.setStyle({
 95:       background: '#{Constants::Display::HIGHLIGHT}'
 96:     })})"
 97:     onmouseout = "$$('.item_#{item.id}').each(function(s) { s.setStyle({
 98:       background: '#{Constants::Display::BORDER}'
 99:     })})"
100:     rounded(item_display(item, :compare, :onmouseover => onmouseover, :onmouseout => onmouseout), "item_#{item.id}")
101:   end

[Source]

   # File app/helpers/application_helper.rb, line 7
7:   def joke_link(text, link)
8:     fast_link(text, "joke/#{link}", 'class="joke_link"')
9:   end

[Source]

    # File app/helpers/application_helper.rb, line 11
11:   def languages
12:     Constants::Locales::ALL.sort_by(&:last)
13:   end

[Source]

    # File app/helpers/application_helper.rb, line 45
45:   def nav_link(text, link)
46:     cmp = if(link.count('/') < 2)
47:       case link
48:       when '/about'
49:         '/home/index'
50:       when '/stats'
51:         '/home/stats'
52:       else
53:         "#{link}/index"
54:       end
55:     elsif (link =~ /responses\/\d*/)
56:       '/responses/show\d*'
57:     end
58:     if (cmp || link) =~ /\/#{params[:controller]}\/#{params[:action]}/
59:       link_to text, link, { :class => 'active' }
60:     else
61:       link_to text, link
62:     end
63:   end

[Source]

    # File app/helpers/application_helper.rb, line 19
19:   def non_default_languages
20:     @controller.non_default_languages
21:   end

[Source]

    # File app/helpers/application_helper.rb, line 65
65:   def notify(page, message, delay = Constants::Config::FLASH_DELAY)
66:     page << "Message.notify('#{escape_javascript(message)}', #{delay});"
67:   end

[Source]

    # File app/helpers/application_helper.rb, line 77
77:   def option_with_(id, append = nil)
78:     "'#{append}#{id}_id=' + $('##{id}').attr('options')[$('##{id}').attr('selectedIndex')].value"
79:   end

[Source]

    # File app/helpers/application_helper.rb, line 85
85:   def question_options_for_select(method = 'id')
86:     options_for_select(questions_for_select(method), @question && @question.id)
87:   end

[Source]

    # File app/helpers/application_helper.rb, line 81
81:   def questions_for_select(method = 'id')
82:     Question.all.map { |q| [sanitize(q.for_locale(I18n.locale), :tags => []), q.send(method)] }
83:   end

[Source]

     # File app/helpers/application_helper.rb, line 103
103:   def rounded(content, classes = nil)
104:     render(:partial => 'shared/rounded', :locals => { :classes => classes && " #{classes}", :content => content })
105:   end

[Source]

    # File app/helpers/application_helper.rb, line 33
33:   def share_this_tag
34:     ENV['RAILS_ENV'] == 'production' && javascript_tag('', :src => "http://w.sharethis.com/widget/?tabs=web%2Cpost%2Cemail&amp;charset=utf-8&amp;style=default&amp;publisher=d02fb4fa-f0d9-477c-934e-40e5b861eb0c")
35:   end

[Source]

    # File app/helpers/application_helper.rb, line 37
37:   def top_country_item(country, items, question)
38:     items.sort_by { |item| item.win_percent_for_country(country.upcase, question.id) }.last
39:   end

[Source]

    # File app/helpers/application_helper.rb, line 41
41:   def top_country_item_from_list(idx, items, win_percents)
42:     win_percents.sort_by { |key, value| value[idx] }.last.first
43:   end

[Source]

    # File app/helpers/application_helper.rb, line 23
23:   def translations
24:     @controller.translations
25:   end

[Validate]