How to write a ruby code that add a new user's data to a user_custom_fields

I find the answer.

Adding a new row or editing older rows in Ruby On Rails isn’t like PHP because Rails is so much objective even when you want to work with database.

I will explain my answer for other who have my problem:

FORGET about sql query, in Here everything are objects, every row in database is an object. for adding a new row, you should create a new object and if you want to edit a row, you should find that row as an object.

So if everything is object here, What is the class name for creating new one?
If you want to edit the user_custom_fields table, the class name is UserCustomField.
to edit an exiting data, you should find it first like this:

MyObject = UserCustomField.where(name: "user_field_5", user_id: 364).first
MyObject.value = "new Value"
MyObject.save

this code will change the custom_user_field with name user_field_5 and user_id 364 .
now for adding new one you should do this:

NewObject = UserCustomField.create(user_id: 634, name: 'user_field_6', value: 'my value')
this code will create a new row in database and you shouldn’t define id, created_at , updated_at because rails will define them automatically and also increase the sequence. :wink: