Module: CaseyJones::ApplicationHelperMethods

Defined in:
lib/casey_jones/application_helper_methods.rb

Instance Method Summary collapse

Instance Method Details



18
19
20
21
22
23
# File 'lib/casey_jones/application_helper_methods.rb', line 18

def add_child_link(name, child, form_builder, options={})
  # puts "||#{form_builder}||"
  new_form = new_child_fields(child, form_builder, options)
  raw((:div, new_form, {:id=>"#{child}_template", :class=>"form-template"}, escape=false))+
  link_to(name, options={}, html_options={"href"=>"#", "class"=>"add-child-link", "data-class-name"=>child})
end

#form_for_urlObject



3
4
5
6
7
8
9
# File 'lib/casey_jones/application_helper_methods.rb', line 3

def form_for_url
  if parent?
    [parent, resource]
  else
    resource
  end
end

#new_child_fields(child, form_builder, options = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/casey_jones/application_helper_methods.rb', line 25

def new_child_fields(child, form_builder, options={})
  partial = options[:partial] ||= child.underscore
  output = ""
  form_builder.fields_for(child.pluralize.to_sym, child.camelize.constantize.new, :child_index => "__#{child}_id__") do |f|
    output += render(:partial => partial, :locals => { :f => f })
  end
  output
end


11
12
13
14
15
16
# File 'lib/casey_jones/application_helper_methods.rb', line 11

def remove_child_link(name, form_builder)
  value = form_builder.object.new_record? ? "1" : "false"
  klass = form_builder.object.class.name.underscore
  form_builder.hidden_field(:_destroy,  {:value=>value, "data-remove"=>klass}) +
  link_to(name, options={}, html_options={"href"=>"#", "class"=>"remove-child-link", :tabindex=> "0"})
end

#text_area_with_auto_complete(f, field, controller, opts = {}) ⇒ Object



40
41
42
43
44
45
# File 'lib/casey_jones/application_helper_methods.rb', line 40

def text_area_with_auto_complete(f, field, controller, opts={})
  opts["data-auto-complete-delim"] ||= 'nl'
  opts["data-auto-complete"]='ta'
  opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)")
  f.text_area field, opts
end

#tfwac(f, field, controller, opts = {}) ⇒ Object



34
35
36
37
38
# File 'lib/casey_jones/application_helper_methods.rb', line 34

def tfwac(f, field, controller, opts={})
  opts["data-auto-complete"]='tf'
  opts["data-auto-complete-url"]=eval("#{controller.to_s.underscore.tableize}_path(:format=>:json)")
  f.text_field field, opts
end