Our great sponsors
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
Ruby Quiz is a simple Rails application that asks the user five quiz questions. It provides feedback after each question and shows the user their total score at the end. Questions are stored in a database table of the same name, and the results are recorded in an attempts table. The web page is shown below.
However, we can take this a step farther. Controller action methods are essentially their own Rack applications that respond to HTTP requests. Rack is the middleware that sits between Rails and the web server. We can use the rackup file to start processes that wire the endpoint directly to a controller method we write. Using this approach allows the new microservices to leverage existing model classes as well as CI/CD pipelines.
Note that we don’t even add a route for this method. Why is that? Because we wire the domain and port binding directly to the controller action. The rackup file is where the magic happens. Unless specified, the Puma web server looks for the config.ru file. The line of significance in the default version of this file runs the entire Rails application.