Question: Generate custom builder in rails


Generate custom builder in rails

Answers 0
Added at 2016-12-29 13:12

I wanted to make a new custom builder in rails for a two text field to be used for range(seprated by -) field in rails

I tried something like

<%= form_for :range, :url=>{:controller=>"skills",:action=>"create"},:html=>{:multipart => true}, :builder => ComponentBuilder do |f| %>

<%= f.text_range_field :min_value,:max_value, :value => min_value, :id => 'value-min' %>


my custom field builder is like

class ComponentBuilder < ActionView::Helpers::FormBuilder
def text_range_field(obj1,obj2,label,*args)
opts = args.last.is_a?(Hash) ? args.pop : {}
human = (opts[:label] unless opts.blank?) || label.to_s.humanize
args << (opts[:class].blank?? opts.merge!({ class: "tab_general_input" }): opts)
mandatory_text = (opts[:mandatory] == true)? ("<span class=\"mandatory\"> *</span>") : ""
content_tag("ul" ,
  content_tag("li" ,
    content_tag("label" ,
      mandatory_text.html_safe + human.to_s.html_safe,
      for: "#{@object_name}_#{label}" ), class: "tab_general_title") +
    content_tag("li" ,text_field('','',*args)+text_field_tag('','',*args), class: "tab_general_info"))   


but it does not produces any result, any ideas where i might be doing wrong

Answers to

Generate custom builder in rails

Source Show
◀ Wstecz