If you have a basic grounding in the Ruby-on-Rails framework and are ready to dig in and build your first application, keep reading. This four-part article series will walk you through it. This article is excerpted from chapter three of the book Beginning Rails: From Novice to Professional, written by Jeffery Allan Hardy, Cloves Carneiro Jr. and Hampton Catlin (Apress; ISBN: 1590596862).
Building a Basic Ruby-on-Rails Application (Page 1 of 2 )
The best way to learn a programming language or a web framework is to dig in and write some code. After reading the first two chapters, you should have a good understanding of the Rails landscape. This chapter builds on that foundation by walking you through the construction of a basic application. You’ll learn how to create a database and how to connect it to Rails, as well as how to use a web interface to get data in and out of the application.
You’ll receive a lot of information in this chapter, though not more than you can absorb, we hope. Our goal here is demonstrate, not to overwhelm. As you’ll see, Rails makes it incredibly easy to get started, and that’s a feature we want to highlight. There are a few places where Rails really shines, and getting something running is one of them. By the end of this chapter, you’ll have a working web application to play with, explore, and learn from. We’ll build on this application throughout the rest of the book, adding features and refining functionality.
An Overview of the Project
We’re going to build a simple event-management system that will let us create and manage upcoming events, not unlike Upcoming.org or Evite. Our first iteration will focus on the basics: creating and editing events.
Before we start coding though, let’s sketch out a brief summary of the goals and flow of the application. We’re going to stay at a very high level. The idea is not to focus on the nitty-gritty, but instead to concentrate on the general case.
Our application will have two kinds of users: those who create events and those who wish to attend events. In some cases, people will play both roles. All users will need to create an account by registering on the site. It would also be nice if people could notify their friends of interesting events with a “send to friend” feature that sends out a friendly email notification to interested parties.
These are some of the features we will add in later chapters. Other application requirements will likely come up as we continue, but these will be enough to get started. In the real world, specifications are seldom correct the first time around, so it’s best not to dwell on them. You’ll see right away that Rails doesn’t penalize you for making changes to an application that’s already under construction, so we can engage in an iterative style of development, adding and incrementing functionality as we go.
We’ll start with what matters most: events. You might be wondering why we don’t start with users. After all, without users, who will create the events? We could begin with users, but if you think about it, without events, what could users do? Events are clearly the epicenter of the application, so it makes the most sense to start there and work out the details as we go. Ready? Let’s get started!