When using arrays as the data type in the Rails model in the form field, I get empty braces `{}`

Now we can set the array as a data type in Rails. So, here is how I installed the array in my database:

t.string :tags, array: true,default: []

Now in the form I get empty curly braces {}. If I remove the curly braces, the system will not accept it. He asks for brackets. When editing, I also see braces with tags. How to remove it?

View:

<%= f.label :tags, 'Tags :' ,class: "updLbl" %>
<%= f.text_field :tags, class: "updInp" %>
+4
source share
3 answers

Fast decision

You can use multiple selections as follows:

f.select :tags, @model.tags, {include_blank: 'Please Select'}, {multiple: true, class: 'selectpicker chosen-select'}

Or use the join method for an array to return a string separated by a special string, as follows:

<%= f.text_field :tags, class: "updInp", value: @model.tags.join(,) %>

ti t.column t.string :

t.column :tags, array: true,default: []

method-i-column, .

+4

, - , . - .

- , (), javascript , . , SimpleForm , , : http://railsguides.net/simple-form-array-text-input/

+1

, .

<%= f.text_field :tags, class: "updInp", value: @model.tags.join(,) %>

,

0

Source: https://habr.com/ru/post/1568966/


All Articles