Module: RacesHelper
- Defined in:
- app/helpers/races_helper.rb
Instance Method Summary collapse
- #generate_nested_form(form_builder, method, options = {}) ⇒ Object
-
#link_to_new_nested_form(name, form_builder, method, options = {}) ⇒ Object
Support methods for nested forms lifted from transfs.com/devblog/2009/06/26/nested-forms-with-rails-2-3-helpers-and-javascript-tricks/.
- #truncate_words(text = '', length = 64, omission = "...") ⇒ Object
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, = {}) [:object] ||= form_builder.object.class.reflect_on_association(method).klass.new [:partial] ||= method.to_s.singularize [:form_builder_local] ||= :f form_builder.fields_for(method, [:object], :child_index => 'NEW_RECORD') do |f| render(:partial => [:partial], :locals => { [:form_builder_local] => f }) end end |
#link_to_new_nested_form(name, form_builder, method, options = {}) ⇒ Object
Support methods for nested forms lifted from transfs.com/devblog/2009/06/26/nested-forms-with-rails-2-3-helpers-and-javascript-tricks/
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, = {}) klass = form_builder.object.class.reflect_on_association(method).klass Rails.logger.warn "!! link_to_new_nested_form: klass is #{klass.inspect}" [:object] ||= klass.new [:partial] ||= method.to_s.singularize [:form_builder_local] ||= :f [:element_id] ||= method.to_s [:position] ||= :bottom link_to_function name do |page| html = generate_nested_form(form_builder, method, :object => [:object], :partial => [:partial], :form_builder_local => [:form_builder_local] ) page << %{ $('#{[:element_id]}').insert({ #{[: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 |