Monday, February 7, 2022

RoR Views and Controllers



To create web pages, Rails provides a templating system that makes it easy to use, allows you to insert common components without repeating their code, information from a database, and display and process forms. These templates represent the "view" in the model-view-controller system.


If you're a front-end developer, this is the part of Rails you should be focusing on. You can assume that your files will be passed variables that contain all the information needed for display. Just as PHP files combine PHP and HTML code, the typical look of Rails is a mixture of Ruby and HTML. Let's continue the explanation using the example of our online store. For example, here is a code snippet that displays the title and author of a book:

<%= book.title %>

<%= book.author %>


The Ruby code is marked with <%= and %>; the rest is HTML.


Rails has built-in support for Prototype and Scriptaculous JavaScript libraries, as well as an object called Ruby JavaScript (RJS) for creating Ajax interfaces. You can write almost anything in Ruby, including client-side code like JavaScript.


The "controller" is part of the Ruby code. Its main job is to interact with the model to prepare the data the view needs.” Any information is collected by the controller into a set of variables before the view is called. The controller also responds to Ajax requests after the page has loaded. Controllers provide many other functions, from user authentication to error handling.

Is Ruby on Rails suitable for beginners

Ruby is a language like the rest. It is important to study the base. I think that you can learn programming in any language if you have a ba...