In order to get a good understanding of the ‘under the hood’ aspects of Rails, there are some important things to know we can learn using Sinatra. This project was to create an Sinatra based app using CRUD and MVC. I chose to make an app to track your expenses, which also displays monthly and annual totals.
Sessions in Sinatra are an important and useful addition. Many websites have the ability to let users create accounts, in order to do things such as buy products, receive email alerts, etc.
Sinatra works as a bare bones framework for Model-View-Control (MVC) work.
Deriving key/value pairs from data is a useful task in Ruby. The basic method for this looks something like :
The main take away for me from this section is utilizing attributes of an object class by using the “attr_accessor” to make attributes available throughout the different class methods you may be building. Attr_accessors represent instances of the defined attribute. For instance, if we create the proper attr_accessor’s and then define our initialize method utilizing the instance variables (@’s) we can access instance values. In the case of this initialize method, we are accessing those instances upon the initialization of a cash register instance, and setting those variable equal to the desired values.