I created an additional variable (string) in the user profile for this manual: https://gist.github.com/withoutwax/46a05861aa4750384df971b641170407

In this line, I store user information.
I can reach her like this: current_user.information

But how can I make a method that takes one line and saves it to the end of the information ?

So far, but it does not work (the result is displayed, but not written to the user variable):

 current_user.information << id 

Through editing the profile, everything is saved.

  • most likely, you forgot to call save the user after adding information - Alexander Shvaykin

1 answer 1

You can do it like this:

 current_user.update(information: current_user.information + id) 

That's just why such a strange storage method as a string is chosen? Why not json?

  • I need to store in the id variable of my favorite user photos. I decided it would be easier than creating another table with several fields. But now I doubt my choice. Thanks for the help, I will think. - rails555
  • So it will definitely not be easier. For photos you already have a table? What prevents you from simply adding the has_many :favorite_photos, class_name: 'Photo' link and enjoying all the built-in buns? :) - Vasilisa
  • And yes, if my answer solves your question, do not consider it a difficulty, accept it - Vasilisa