DEV Community


Using the update_attribute() API using the rails console

Vicente G. Reyes
Building | ICVN Tech Studio | Musician | |
・1 min read

I had a task at work to add data from the rails console after generating migrations and was puzzled on how to do it. After spending some time on the problem, I asked for help and this is what I got:

object.description = "Lorem Ipsum"
Enter fullscreen mode Exit fullscreen mode

The problem was, it returned false which I had a hint that it didn't work.

I checked the frontend and it didn't show the data I entered and ran reload on the rails console again but it still didn't update the data.

I knew I had to check the docs and figure out how to do it.

I found this answer on SO which helped me with my problem.

object.update_attribute(:book_description, "Lorem Ipsum")
Enter fullscreen mode Exit fullscreen mode

This updated the data on the frontend which was the goal of the task.

Discussion (0)