I
I
Ivan Nesterovich2014-06-20 13:10:10
PostgreSQL
Ivan Nesterovich, 2014-06-20 13:10:10

[Rails] How to properly update postgresql array?

There is an array field in the postgresql table:
t.string :favorits, array: true, default: []
From time to time I need to add and remove elements from this field:

@user.favorits.delete_at("has_value")
@user.favorits.unshift("new_value")
@user.save

However, all these changes are not saved. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dimitriy, 2014-06-20
@vanderv

...
@user.favorits_will_change!
@user.save

E
Eugene Burmakin, 2014-06-20
@Freika

Maybe try @user.save!?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question