Best practice for clearing a form field when using Postgres Array column in a Rails 5.2 app?


Best practice for clearing a form field when using Postgres Array column in a Rails 5.2 app?



I'm building a Rails 5.2 application that has a Postgres array column to store tags on a Post model.
The migration I created looks like this...


class AddTagsToPosts < ActiveRecord::Migration[5.2]
def change
change_table :posts do |t|
t.string :tags, array: true, default:
end
end
end



Since setting the default value is required (?...I failed to find a way to get a PG array column to work without setting the default value of tags to an empty array), what is the best practice to remove the default value () from being auto filled on a Rails new/edit form without using JS?




1 Answer
1


<% 3.times do |num| %>
<%= form.text_field :tags, multiple: true, class: "form-control", value: @post.tags[num] %>
<% end %>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

PySpark - SparkContext: Error initializing SparkContext File does not exist

django NoReverseMatch Exception

Python Tkinter Error, “Too Early to Create Image”