Last time, we explored the MVC architecture utilized in the Rails framework and were able to finally take some data from the Steem blockchain, transform and filter it in some way, and then serve that information up as a web page. We now have a working web application that does something. An early milestone in Project Greenshift to this point. But we still have a long way to go before we arrive at the product that was brainstormed at the beginning of this process.
Today, we'll briefly cover routing, an important element in serving web pages to clients. A client in the client-server relationship is anyone who requests information held and processed somewhere else. The server does all the work and the client receives the end product. Routing is one way to determine what information a client (and user) gets.
If you recall last time, the web address we used to reach our index view was the following:
localhost:3000/content/index
Routing essentially is the process of using these web paths to collect specific information from the server. By adjusting the path, routing will take you to the corresponding web page associated with that path. The home page or root of a web application is the route with an essentially empty path /. The root of the web application on our local server would be:
localhost:3000
Today, we are going to update our web application so that the index page we developed last time will be our homepage for the time being. To achieve this, we need to alter the route stored in the routes.rb file in the config folder in the top level of our project. A route is currently there, but requires the longer URL to reach. To fix this, we simply specify the controller and the view as the root for this application:
And it is as easy as that. If we spin up a local version of the application using rails s, and open up a web browser and quickly request a web page from the root of the application, we get the familiar view we got last time:
Although that was fairly simple, routing does get more complicated the beefier our application becomes and the more web pages we have available for the client to access. However, for this first stage of the project, it is likely that only a few web pages will be necessary to begin traversing the blockchain just using our relationships.
Next time, we start working on our third relationship. This one will require getting the highest percentage vote by an author in the past seven days. A lot of the time, this will be the most recent 100% upvote, but sometimes it will not be. We will work off our first relationship, which simply gets the most recent vote and work our way from there.