Module: RacesHelper

Defined in:
app/helpers/races_helper.rb

Instance Method Summary collapse

Instance Method Details

#generate_nested_form(form_builder, method, options = {}) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'app/helpers/races_helper.rb', line 28

def generate_nested_form(form_builder, method, options = {})
  options[:object] ||= form_builder.object.class.reflect_on_association(method).klass.new
  options[:partial] ||= method.to_s.singularize
  options[:form_builder_local] ||= :f
 
  form_builder.fields_for(method, options[:object], :child_index => 'NEW_RECORD') do |f|
    render(:partial => options[:partial], :locals => { options[:form_builder_local] => f })
  end
end


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/helpers/races_helper.rb', line 7

def link_to_new_nested_form(name, form_builder, method, options = {})
  klass = form_builder.object.class.reflect_on_association(method).klass
  Rails.logger.warn "!!  link_to_new_nested_form: klass is #{klass.inspect}"
  options[:object] ||= klass.new
  options[:partial] ||= method.to_s.singularize
  options[:form_builder_local] ||= :f
  options[:element_id] ||= method.to_s
  options[:position] ||= :bottom
  link_to_function name do |page|
    html = generate_nested_form(form_builder,
                  method,
                  :object => options[:object],
                  :partial => options[:partial],
                  :form_builder_local => options[:form_builder_local]
                 )
    page << %{
      $('#{options[:element_id]}').insert({ #{options[:position]}: "#{ escape_javascript html }".replace(/NEW_RECORD/g, new Date().getTime()) });
    }
  end
end

#truncate_words(text = '', length = 64, omission = "...") ⇒ Object



38
39
40
41
42
43
# File 'app/helpers/races_helper.rb', line 38

def truncate_words(text='', length=64, omission="...")
  return '' if text.blank?
  words = text.split
  omission = '' unless words.size > length
  words[0..(length-1)].join(" ") + omission
end