0

I use nested_form along with bootstrap tab. To making bootstrap tab work properly I need to give each tab a unique id, otherwise only one of the 4 tabs will work correctly.

I have been able to get the id of each nested form input and give it as a unique id to each tab by using this:

- field_title = f.text_field :title
- id2 = field_title.match(/id="(?<id>[^"]*)"/)

In my bootstrap tab I have used this solution:

.nav-tabs-custom
  %ul.nav.nav-tabs
    %li.active
      %a{"data-toggle" => "tab", :href => "#tab_1_upl_#{id2}"} Upload
    %li
      %a{"data-toggle" => "tab", :href => "#tab_2_url_#{id2}"} link
    %li
      %a{"data-toggle" => "tab", :href => "#tab_3_lib_#{id2}"} image library

  .tab-content
    %div{id: "tab_1_upl_""#{id2}", class: " tab-pane active"}
      image

    %div{id: "tab_2_url_""#{id2}", class: " tab-pane"}
      link

    %div{id: "tab_3_lib_""#{id2}", class: " tab-pane"}
      library

But the issue now is that, the id for anchor is like:

id=" #tab_2_url_id="table_choices_attributes_1464338477560_title" "

As you can see this part: ="table_choices_attributes_1464338477560_title" is the issue here and prevent the tab to work properly.

How can I only get the text inside the id or just replace = "?

I have tried with gsub, tr, tr! and getting error undefined method.

Thanks for help.

Rubioli
  • 670
  • 6
  • 21
  • Tried this ? http://stackoverflow.com/questions/19637677/ruby-remove-characters-from-a-string – Ninja Boy May 27 '16 at 09:04
  • yes, and I get error `undefined method "tr"`. I tried this: `id2 = field_title.match(/id="(?[^"]*)"/).tr("=", '')` – Rubioli May 27 '16 at 09:07

1 Answers1

0

tr or gsub can not be used with a variable. So what I did was to use it outside of the string like code blow:

%div{id: "tab_1_upl_""#{id2}".tr('"=', ''), class: " tab-pane active"}
Rubioli
  • 670
  • 6
  • 21