Diogo Wernik Diogo Wernik - 2 months ago 6
Ruby Question

ruby on rails - how to post tagsinput and get an array as result

i created a field called tags_speciality

Here is my migration file:

class AddSpecialityToSubdomains < ActiveRecord::Migration
def change
add_column :subdomains, :tag_speciality, :string, array: true
end
end


Then i added on my view file the field:

<%= f.text_field :tag_speciality, data: {role: 'tagsinput'}, multiple: true %>
<%= f.submit class: 'btn btn-primary' %>


After submit the form i get that result:

[["tag1,tag2,tag3"]]


But look like that would be better get this result:

[["tag1","tag2","tag3"]]


How can i achive that?

Thanks

Answer

You can do something like this on your result:

arr = [["tag1,tag2,tag3"]]
result = arr[0][0].split(',')

#=> ["tag1", "tag2", "tag3"]
Comments