module ApplicationHelper
Public Instance Methods
c_num(number, precision=2, skip_zero=false)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 63 def c_num number, precision=2, skip_zero=false return '' if skip_zero && number==0 return number unless number.is_a? Float number_with_precision( number, :precision=>precision, :delimiter => ' ') # c_number_with_precision( number, precision ) end
lf(date, options={})
click to toggle source
same as I18n.l() but ignores nil
# File lib/r4/template/config/initializers/html_helpers.rb, line 42 def lf date, options={} l(date, options) if date end
num(number, options={:precision=>2})
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 57 def num number, options={:precision=>2} return number unless number.is_a? Numeric return '' if options[:skip_zero] && number==0 number_with_precision( number, options ) end
num0(number, skip_zero=false)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 78 def num0 number, skip_zero=false return '' if skip_zero && number==0 return number if number.is_a? Fixnum c_num number, 0, skip_zero end
num2(number, skip_zero=false)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 74 def num2 number, skip_zero=false c_num number, 2, skip_zero end
num3(number, skip_zero=false)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 70 def num3 number, skip_zero=false c_num number, 3, skip_zero end
num_warn(condition)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 16 def num_warn condition "num #{'warn' if condition}" end
numx(number, precision=3, skip_zero=false)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 84 def numx number, precision=3, skip_zero=false c_num number, precision, skip_zero end
records_filter()
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 20 def records_filter concat t('records') + ': ' + select_tag('filter[per_page]', options_for_select(%w[30 50 100], filter.params[:per_page]) ) + "\n" end
session_debug()
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 92 def session_debug "#{session['debug_params']}<br />#{link_to_function 'debug', "$('#debug_div').toggle()", class: 'btn thin'}<hr class='separation'/><div class='box white spaced' id='debug_div' style='display:none'>params:#{params.inspect}<br /><br />session#{session.inspect }<br /><br />referrer:#{request.referrer}".html_safe if DEVEL && session['debug_params'] session['debug_params']='' end
shorten(text, length=20)
click to toggle source
make long text short with ‘…’
# File lib/r4/template/config/initializers/html_helpers.rb, line 10 def shorten text, length=20 return '' unless text.present? res = text.scan /^(.{1,#{length}})(.*)/ "#{res[0][0]}#{res[0][1].present? ? '...' : ''}" end
t_header(name)
click to toggle source
# File lib/r4/template/config/initializers/html_helpers.rb, line 3 def t_header name header = t("activerecord.attributes.#{name}") header[0] = header[0].upcase header end
yes_no_select()
click to toggle source
selecting - yes, no, nil
# File lib/r4/template/config/initializers/html_helpers.rb, line 47 def yes_no_select [nil, [t('yes'), 'yes'], [t('no'), 'no'] ] end