Monday, February 7, 2022

Nothing is perfect


Rails has its drawbacks. Ruby is slower than most other languages. This is likely to change with the release of new versions, but at the moment this drawback is critical for those applications that value processing time. In reality, this is not a problem for most websites.


There is also a problem with hosting Rails applications. Due to the size of the Rails framework code, it must be kept in memory at all times and loaded in response to a request. You need 100-200 MB of internal memory to host applications even with low traffic. By comparison, you can place PHP applications anywhere you want because they don't take up memory when they're not available.


Because of these server requirements, finding shared hosting for Rails applications is usually quite problematic. VPS (Virtual Private Server) is the best choice. Server setup is more complicated than for PHP. But now there are many Rails-centric hosting companies that provide turnkey solutions.


Another result of these server requirements is that Rails hosting tends to be more expensive than other platforms and languages.

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.

Nothing is perfect

Rails has its drawbacks. Ruby is slower than most other languages. This is likely to change with the release of new versions, but at the mom...