Almost every Rails application contains some interaction with a database. The default Rails database management system is SQLite3, but you may want to upgrade to PostgreSQL. There are two advantages to using PostgreSQL in Rails. First, if you’re planning on running your app on Heroku, your app must be configured to use the Postgres database. Second, PostgreSQL is much more powerful in terms of maintaining data integrity and providing for complex database designs. In particular, PostgreSQL allows for a much wider variety of datatypes. On the other hand, PostgreSQL can be over-kill if your setup is light and/or your app requires fast read operations.
The most mind-boggling aspect of web development isn’t learning a new language or memorizing the different functions or methods in a language, at least for a beginner developer. Coordinating different languages in a flexible and effective fashion is important in creating beautiful and functional web applications, but the path isn’t always so smooth. Often, the benefits reaped from libraries and frameworks that are built on this principle come with incidental disadvantages that just have to be compromised.
In Rails, nested forms allow multiple models to be included in one form, so that a single submission can create more than one object in the database. There are different ways to implement nested forms. Scaffolding is a quick and easy way to get your app up and running, and will work with this tutorial. In the case of my recent Planet Shop Rails App, which I will be using as an example here, I had to implement a nested form and another nested form within that form.
Oovart’s Planet Shop at the End of the Universe is a Rails application that allows users (customers) to sign up, order planets with different features, and make additional orders to add features to their planets. Available features include forests, fjords, and volcanoes, among others. Customers can also create their own custom features. A price tag is randomly assigned to each order of a planet or feature. Because the planet shop is near the end of the universe, customers who get tired of their planets can press a button to watch the universe end itself while it destroys all their planets.
Relationships are complicated, even in a two-dimensional universe. Trying to understand what Active Record associations are, which ones to use under what circumstances, and how they work together are confusing concepts for beginners to wrap our heads around.