Join Kevin Skoglund for an in-depth discussion in this video Creating a project, part of Ruby on Rails 3 Essential Training.
Now that we have everything installed that we need to run Ruby on Rails, we're ready to create our first project. And the project we're going to create is a simple Content Management System or CMS for short. And we'll be working with this project throughout the training title. We're going to use it early on for some of our demos while we get our feet wet. And then we'll dive in and really turn it into a full fledged application a little later on. For now, let's just see how to create a Rails project. The way we will create a new Rails project is from the command line. You'll want to start by opening up your command line application, that is command prompt on Windows. Or the terminal on a Mac.
Next, let's decide where we want to put our Rails project. Unlike developing with HTML or PHP, where there's a special web folder where we must put all our code, so that the web server can find it and serve it to us. With Rails, we have a lot more flexibility. Because of the way the web brick web server, which comes with Rails, works. We'll be able to access our application, regardless of where we place it on our hard drive. But still does make lot of sense to keep our code grouped with our other web code so it's all in one place. We don't want projects scattered all over the place. So if you have a working web directory already, put it there. If not, and you're on a Mac, Apple gives Mac users a folder called Sites in each user's directory.
If I type pwd, you'll see the path to where I am now, that's inside Users, inside kevin, that's my user folder. And inside there is a folder called Sites with a capital S. So, cd into Sites will navigate into that Sites folder. And then if I type ls -la or just ll if you configured the alias for ll earlier. We'll do the same thing and we'll now see what's inside that folder. Now, if you're in Windows, you can put the project inside your My Documents folder. Either directly or first by creating a sub folder in there called, sites, or www, or web code, and putting it inside there.
Don't put it at the root of the hard drive or inside the Program Files folder because Windows has special security settings for those directories that may get in our way. But anywhere inside My Documents should be fine. And from the command line in Windows, if you want to see the same list that I have here, the command is dir. And that'll show you the contents of that directory. So, this is where I'm going to put my Rails application. And the way that we'll create it is by using the Rails command from the command line. The Rails command will be used for several different tasks. But right now, we're going to be using it just for creating a new Rails application. So, rails new and then the name of our application.
Now I'm going to call mine simple_cms. Now this is a slight change. Previous versions of Rails you didn't type new. You just typed rails and then the name of the application you wanted to create. That caused some confusion so they added this. So it's rails new will create a new project. Now, I called it simple_cms. The name that you choose is important because Rails is going to use that name to configure our applications. To make some guesses about what names we want to use for our databases and other things like that. We can change it later, we'll just need to change those configuration files. To match whatever new configuration we have.
We also need to do something very important here before we hit Return on this line. We want to put a space, and then a -d, and a space, and then MySQL. What we're saying is create a new Rails application, called simple_cms. That is preconfigured to use a MySQL database. If we didn't specify the database, it would default to use SQLite. That's the default. And if we didn't specify MySQL, it wouldn't be a huge deal. Rails has support for both MySQL and SQLite built in, it's already there waiting for us. But we would need to change the information in one file, the database configuration file.
That's where we would configure which one we'd use. But by specifying it here, that configuration file will be pre set up for us to use MySQL. We won't need to remember to go in and make changes. So let's make sure that we always use that as long as we're using a MySQL database. Now we can hit return at the end of that. You'll see they created a bunch of files for us. We'll come back and look at what all those files are later. For now, let's just look at the directory again. That's ls -la, or ll, if you have that alias. Or dir if you're on Windows. And you'll see the folder here created called simple_cms.
That is our Rails application. Let me show it to you in the Finder also. Let me just click here. Open a new Finder window. I'm inside my user folder, kevin, which is inside my hard drive, inside Users, and here's my sites folder. I double-click on that, here it is, simple_cms. Now if I were to throw away this folder, my Rails application would be gone. Everything for the Rails application is self-contained in this one folder. Not Rails itself, we installed that is a gem, and that's installed in our system somewhere else. But the Rails application that we're creating, the thing that's specific to our project is all contained in that one folder.
Back in the command line let's move into that folder. Let's do cd simple_cms. We'll go into the root of my Rails application. And whenever you hear me say the root of the application, I'm talking about being directly inside. The simple_cms directory. Once again, we can type ls -la, or dir, and it'll show you a list of the contents. Or in the Finder, we can see it just by opening up that folder. Let's double-click on that. So there we are. This is the root of my application. And we see all of the files that it created for us. So just like that, we've created our first Rails project.
Now, there's still more configuration involved. And we'll still need to, obviously, create the code that'll tell our app what to do. But a lot of the application folders and code have been created for us already. In the next movie, we'll see how we can access the project and examine the code that Rails put there for us.
- Understanding MVC (Model View Controller ) architecture
- Routing browser requests through the framework
- Responding to requests with dynamic content
- Defining associations and database relationships
- Creating, reading, updating and deleting records
- Working with forms
- Validating form data
- Reviewing built-in security features
- Authenticating users and managing user access
- Debugging and error handling
Skill Level Beginner
1. What Is Ruby on Rails?
2. Installing Ruby on Rails on a Mac
3. Installing Ruby on Rails on a Windows Machine
4. Getting Started
5. Controllers, Views, and Dynamic Content
6. Databases and Migrations
7. Models, ActiveRecord, and ActiveRelation
9. Controllers and CRUD
10. Layouts, Partials, and View Helpers
12. Data Validation
13. User Authentication
14. Improving the Simple CMS
15. Debugging and Error Handling
16. Introducing More Advanced Topics
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.