Join Kevin Skoglund for an in-depth discussion in this video Creating a project, part of Ruby on Rails 4 Essential Training.
Now that we have everything installed that we need to run Ruby on Rails, we're ready to create our first project. The project we're going to create is a simple content management system, or CMS for short. 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 this into a full-fledged application a little later on. For now, let's see how to create a Rails Project. The way we'll create a 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 Mac.
Next, let's decide where we want to put our Rails project. Unlike developing with HTML or PHP, where there's often a special folder where we must put all of our code so that the web server can find it. With Rails, we have a lot more flexibility, because of the way that the WEBrick web server which comes with Rails works. We'll be able to access our application from almost anywhere on our hard drive. However, even though it can do anywhere, it does still make a lot of sense to keep it with your other web code. So, if you have a working directory, put it there. If not, we van create one.
I'll type, pwd, so you can see where I am. That's in my users directory, inside kevinskoglund, by default. We can see what's in that directory with ls -la. If you're on Windows, that's dir. You can see that I don't have any place there, that I can put those files If you're on Mac, you may have a sites directory. Apple used to provide a sites directory for all installations of Mac OS X and then they stopped doing that with Mountain Lion. But it's no problem, we can create one in any case, mkdir space sites.
Now the make directory command is for both UNIX and for Windows. Now, if you're on Windows, I should note that you can put your Rails application inside your My Documents folder directly, or by first creating a folder called sites or www and putting it inside there. But don't put it at the root of the hard drive. Or in the program files, because Windows has special security settings for those directories that may get in your way. Once we've created the directory, then we'll just change directories to get inside of there, and now we're inside the directory where we want to create our Rails application.
We will create the application using the Rails command. Let me just clear my screen with Cmd+K. And I will type Rails, the Rails command will be used for several different tasks. But right now we are going to using for creating a new Rails application. So Rails space new and then a space followed by the name of our application. I'm going to call it simple_cms. The name you choose is important because rails is going to use that name to configure our application. To make some guesses about what names we want to use for data bases, and other things.
We also need to do something very important before we hit Return. Put a space and then a dash d and then a space and then type msql. What we're saying is create a new Rails application called simple cms that is pre-configured for using a MySQL database. If we didn't specify a database then it would default to use SQLite. Rails has support for three databases built in, SQLite3, which is the default, MySQL, and PostgreSQL. And those are probably the three most popular options.
They also have additional support by using plugins for Oracle, IBM_DB, SQL Server, andFrontBase. You can find those as RubyGems on the RubyGems website. Now, if we didn't specify MySQL, it wouldn't be a huge deal. Rails has support for both databases built in, and we would just need to change the information in one file, the database configuration file. But let's go ahead and specify MySQL at the start, and then that database config file will already be configured for exactly what we want. So let's hit Return now. It'll take just a moment while it creates the files for us.
You'll see that it tells us a list of all the files that it created. You can scroll up that list if you want. But then it says, bundle install at the end, so, it's created all the files, and now it's telling bundler to install all of the gems that might be missing. Anything else that it thinks that it might need, tells bundler to go ahead and get those all gathered up so that our application can use them. We'll come back and look at the files that it created later. For now let's just type ls dash la again, or DIR if you're on windows. And you can now see that it created a folder called simple_cms, this is our Rails application.
If we throw that folder away, our Rails application is gone. Let's now change directories to go into that directory. CD simple cms and now I'm the root of my Rails application. That's a very common term. You'll hear people talk about Rails application. That's what they're talking about. They're talking about being directly inside this simple cms directory. ls-la or dir will show you a list of the contents. We can also take a look at that in the operating system as well. I'll open up Sites, and inside simple cms, and we'd see the same files that it created here.
And just like that, we've created our first Rails project. There's still going to be more configuration involved, and we're going to have to create the code to tell our app what to do. A lot of the application folders and code have already been created for us, just by telling Rails to create the application. In the next movie, we'll see how we get access our Rails project, even at this very early stage.
- Why use Ruby on Rails?
- Installing Ruby on Rails on Mac and Windows
- Rendering templates and redirecting requests
- Generating and running database migrations
- Creating, updating, and deleting records
- Understanding association types
- Using layouts, partials, and view helpers
- Incorporating assets using asset pipeline
- Validating form data
- Authenticating users and managing user access
- Architecting RESTful applications
- Debugging and error handing
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
13. Data Validation
14. User Authentication
15. Improving the Simple CMS
16. REST and RESTful Routes
17. Debugging and Error Handling
18. Introducing More Advanced Topics
Next steps1m 40s
- 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.