In my app I've got a table named contacts with the areas_of_interest field. This field should store hashes sent by user via form. However my database reject those hashes and leave this field blank every time when I want to save it:
Schema:
create_table "contacts", force: :cascade do |t|
...
t.text "areas_of_interest"
t.index ["user_id"], name: "index_contacts_on_user_id"
end
Contact Model:
class Contact < ApplicationRecord
belongs_to :user
serialize :areas_of_interest
...
end
ContactsController:
def update
respond_to do |format|
if @contact.update(contact_params)
format.html do
redirect_to root_path, notice: 'Contact has been updated'
end
else
format.html do
render :edit, notice: 'Error'
end
end
end
end
private
def contact_params
params.require(:contact).permit(
...
:areas_of_interest,
...
)
end
And the hash sent from client looks like this:
{"first"=>"1", "second"=>"0", "third"=>"0", "fourth"=>"0", "fifth"=>"1"}
What possibly do I do here wrong and how can I fix it?
:areas_of_interesttoareas_of_interest: {}params.require(:contact).permit(...