Latest Posts

Personal blog by Karina Baha.

  • Add and Change Default Column Value in Ruby on Rails

    In Ruby on Rails, it’s easy to set and change a default value for columns in your application database. Say we have an online shop, and we want to set a default price for our products. How can we do that? And if we want to change the default price later, how do we do…

  • Ruby on Rails 7 Credentials

    Ruby on Rails stores the encrypted credentials of your application in the credentials.yml.enc file in the config/ folder. Rails encrypts them using the master key in the config/ folder or the ENV[‘RAILS_MASTER_KEY’] if you provide one.

  • Ruby on Rails has_secure_password Tutorial

    The has_secure_password method adds methods to encrypt a password using the bcrypt algorithm. Also, it adds methods to authenticate against such a bcrypt password. For this method to work, the user model must have a password_digest attribute. In this tutorial, we’ll build a simple application with a user model, and we will discuss in detail…

  • MVC Pattern in Ruby on Rails

    In this article, we will talk about how Ruby on Rails implements the MVC pattern. MVC (Model, View, Controller) was first described and implemented into the Smalltalk-79 user interface paradigm by Trygve Reenskaug. Its purpose was to allow the user to access and edit complex data in an accessible manner.

  • The Root Route in Ruby on Rails

    When developing a web application, the most important thing is to set what to display on the home page. In Ruby on Rails, we specify what we want to show on the home page by defining a root route.

  • Select Records Created within the Last X Months in Ruby on Rails

    Suppose we have a blog application, and we want to show on the index page only the latest posts. Say we want to show the posts created within the last three months. How can we do that? We can use the Active Record query interface. We can use range conditions.

  • Member and Collection Routes in Ruby on Rails

    The routes of a Ruby on Rails application live in the config/routes.rb file. The Rails router matches a request in the browser to a controller action. The Rails default for routing is the resource routing. A resource route will map HTTP verbs like GET, POST, PATCH, PUT and DELETE to a controller action and also…

  • Using form_with With Nested Resources in Ruby on Rails

    In this post, we will deal with using the form_with helper with nested resources in Ruby on Rails. We will build a blog application, and the blog posts will have comments. We will nest the two resources and will create a comment form partial that we will use to create a new comment and edit…