Author: Saim Khalid

  • Forms

    The <form> . . </form> tag in HTML along with the form’s various input elements such text, radio, select, etc. help you to create HTML forms. For example, a basic form to accept user input for a new book record, written in plain HTML would be like this: <form action=”/books” method=”post”><label for=”title”>Title:</label><input type=”text” name=”title” id=”title”><label for=”author”>Author:</label><input type=”text” name=”author” id=”author”><label for=”price”>Price:</label><input…

  • Scaffolding

    While you’re developing Rails applications, especially those which are mainly providing you with a simple interface to data in a database, it can often be useful to use the scaffold method. Scaffolding provides more than cheap demo thrills. Here are some benefits − To understand scaffolding, let’s start by creating a new Rails application named…

  • Layouts

    When Rails renders a view as a response, it does so by combining the view with the current layout. A layout defines the surroundings of an HTML page. It’s the place to define a common look and feel of your final output. By default, Rails uses the app/views/layouts/application.html.erb file as the main layout. It is…

  • Rendering

    In Rails, the controller is responsible for processing the incoming request and creating the response to be sent back to the client. The controller uses mainly the following three ways to create the response The render Method By default, controllers in Rails automatically render views with names that correspond to valid routes. The render method…

  • Views

    A Rails View is an ERB program that shares data with controllers through mutually accessible variables. Rails uses ERB (Embedded Ruby) as its default template engine to interpret and process .html.erb files. If you look in the app/views directory of any Rails application, you will see one subdirectory for each of the controllers. Each of these subdirectories was created…

  • Routes

    The routing module provides URL rewriting in native Ruby. It’s a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails’ Routing works with any web server. Routes are defined in app/config/routes.rb. A route is the part of the URL that determines how an incoming HTTP request is directed…

  • Authentication

    The library application used in this tutorial has the CRUD actions to add, edit, and delete book objects. However, these actions are accessible to anyone, which isn’t safe. Let us add a security layer to the application, so that only authenticated users get the access. Authentication Generator Starting with Rails version 8.0, a default authentication generator is included to streamline the…

  • Cookies and Session

    The Ruby on Rails framework follows the MVC pattern that implements REST architecture. One of the important constraints of REST is statelessness. It implies that each request sent by the client must have enough information for the server to handle and satisfy it, and that the server doesn’t hold on to the request data once it…

  • Controller

    The Rails controller is the logical centre of your application. It coordinates the interaction between the user, the views, and the model. The controller is also a home to a number of important ancillary services. The following diagram explains how the controller interacts with the model and the view layer − The process for creating…

  • Active Model

    In the earlier chapters of this tutorial, we explained the Active Record ORM in Ruby on Rails framework. Active Record is an ORM (Object Relational Mapper) that connects objects whose data requires persistent storage to a relational database. One of the functionality of Active Record is to form Active Model. In this chapter, we will explore the features of Rails Active…