Sha256: 6695b8b97de2fbf4f0630782bb92bd5ba2c539c6772995d865ba98db274b804a

Contents?: true

Size: 1.77 KB

Versions: 10

Compression:

Stored size: 1.77 KB

Contents

module CaseyJones
  module ApplicationHelperMethods
    def form_for_url
      if parent?
        [parent, resource]
      else
        resource
      end
    end

    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

    def add_child_link(name, child, form_builder, options={})
      # puts "||#{form_builder}||"
      new_form = new_child_fields(child, form_builder, options)
      raw(content_tag(: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

    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

    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

    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
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
casey_jones-0.1.2 lib/casey_jones/application_helper_methods.rb
casey_jones-0.1.1 lib/casey_jones/application_helper_methods.rb
casey_jones-0.1.0 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.121 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.120 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.119 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.118 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.117 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.116 lib/casey_jones/application_helper_methods.rb
casey_jones-0.0.115 lib/casey_jones/application_helper_methods.rb