0

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

2 Answers 2

3

You can do something like this on your result:

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

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

EDIT

I found better solution with flatten

arr.flatten.first
#=> ["tag1", "tag2", "tag3"]
Sign up to request clarification or add additional context in comments.

Comments

3

You can use Ruby's split method in your controller. For example:

"tag1,tag2,tag3".split(',')
=> ["tag1", "tag2", "tag3"]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.