Diogo Wernik Diogo Wernik - 1 year ago 58
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

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:


But look like that would be better get this result:


How can i achive that?


Answer Source

You can do something like this on your result:

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

#=> ["tag1", "tag2", "tag3"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download