rails automatically downcase on create

In Ruby on Rails, when you create a record in a database, Rails automatically downcases certain attributes. Here is an explanation of each step:

  1. Rails Models: In Rails, models represent database tables. Each model class is associated with a specific table, and each instance of the model represents a row in that table.

  2. Callbacks: Rails provides callbacks, which are methods that are automatically called at specific points in the lifecycle of a model object. In this case, Rails uses a callback called before_save to modify the data before it is saved to the database.

  3. Attribute Assignment: When you create a new instance of a model, you assign values to its attributes. For example, if you have a name attribute, you might assign it a value like this: my_model.name = "John Doe".

  4. Downcasing: Rails provides a convenient method called downcase that converts a string to lowercase. In the case of the name attribute, Rails applies the downcase method to the value assigned to the attribute before saving it to the database.

  5. Saving to the Database: After the attribute values have been modified, Rails saves the record to the database using the appropriate SQL query.

By automatically downcasing certain attributes during the creation process, Rails ensures consistency and avoids potential issues that may arise from case sensitivity in database queries.