I am not able to store array in database column.
text_field:
= text_field_tag 'product[keywords][]', @product.keywords, class: 'tab-input
product_keywords'
controller params:
params.require(:product).permit(:id, :name, :keywords => [])
model:
serialize :keywords, Array
migration:
class AddKeywordsToProducts < ActiveRecord::Migration[5.1]
def change
add_column :products, :keywords, :text
end
end
So, if someone writes, abc mbc csx and hit submit it should save in db column as array like below:
["abc", "mbc", "csx"]
now I want to store it as array in column but its not storing properly. it stores as:
["abc mbc csx"]
Also what are the best practices to deal with these cases?
serialize :keywords, Array, did you try justserialize :keywordswithout the Array?["voip man cat"]["voip man cat"]or"keywords"=>["voip man cat"]