Intro to Rails: Your First Rails App

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all right so now for the fun part I found that the best way to learn rails is actually by building rails applications as we go through I'll stop and explain what is happening and the various concepts that you're using with that said we are going to now start building our very first rails application so open up your terminal and let's create a directory or folder for our application to live in I'm going to call my directory projects and place it inside of the documents folder but you can call it and place it wherever you like so from the root directory I'm going to CD into My Documents folder CD stands for change directory and what I'm going to do a command called make directory mkdir and I'm going to call this projects then I'm going to CD into that new projects folder and now that we are in our projects folder let's go ahead and create our new application throughout the rest of the book we're going to be building a rails blog from scratch so to begin let's create a rails application by running the rails new and the name of our app I'm just gonna call this block so what just happened there well the rails new command created all the files that are needed for our application then it ran bundle install if we scroll back up you can see it says run bundle install and that command goes out and downloads and installs all the gems that gems that rails depends on so next we need to CD into our newly created rails application so let's do CD blog and hit enter so we can take a look at our new app in the browser let's that run a command called the rails server so I'm going to do rails server and hit enter the rail server command starts the web brake server that comes with rails it allows you to work and develop locally so now open up your browser of choice my personal favorite is Google Chrome so I'm going to open that up and I'm gonna go to localhost port 3000 so welcome board you are now writing Ruby on Rails give yourself pat on the back because you have just created your first rails application however at this point it doesn't do very much so before we start adding additional functionality to our application I want to briefly cover the structure of the rails application go through each of its directories and subdirectories and explain where everything lives so go back to your terminal and hit command T and what that's going to do is it's going to open up a new tab in the terminal so what we need to do is CD into the Documents folder into the projects folder and inside of the blog application so now that we're in the blog you can do the open command so let's do open and then period and that will open it up inside of your finder so what I'm going to do is I'm going to drag and drop this over sublime text which I am using for my text editor so in the sidebar you can see we have a number of different directories and subdirectories within there so I want to briefly go through and cover where everything lives so first off inside of the app directory if we open this up you can see this holds the subdirectories for the NBC conventions the models the views and the controllers as well as assets helpers and mailers the assets directory is where you're going to store your images your JavaScript and your style sheets so if we close that and we go to the bin directory so the bin directory contains app executables which are Ruby scripts for using things like the bundle command the rails command and the rake command next the config directory contains all of the configuration code that your application needs for the tiny amount of configuration that you may need to do remember rails uses convention over configuration for example the environment subdirectory which contains the configuration files for the three environments created by rails the development tests and production the database demo file is where you'll configure the database you'll use for each environment rails uses the SQLite database by default in development but you'll probably want to use a different database such as Postgres or MySQL database in production another important file that we will be using is the route start B file the routes file handles the mapping of incoming web requests to your application this is where you'll add new routes for your application based on the features we are building we'll cover this in more detail in future chapters the database directory this contains a few files in a subdirectory called migrations as you build your application you create database migrations which is how you can create and modify tables in the database this directory also contains a file called schema darby which is a snapshot of your app's database you want to make sure that you never update the schema the RB file directly and only modify it through the use of migrations the schema file is not here right now along with the migrations because we have yet to run any migrations for this application and then finally there is a seed that RB file which is how you can set up your application with pre-loaded data the Lib directory is for reusable code libraries it comes with two directories assets and tasks unless you have some custom stuff for example a custom rake task I'm not sure it makes sense for most of your stuff to live here the log directory contains your application log files which is good for debugging when working in development environment you'll see the development log there will be a different one for your different environments such as test and production the public directory this directory contains things like the 404 dot HTML and the 500 HTML this is because the directory will still work if your application crashes so this is where you'll want to put your error pages the test directory is or if you write tests for your application to make sure it runs the way it should for example test-driven development is the idea of writing a test first and then writing the code to make the test pass so for any test that you write would they would live in this directory the temp directory is to hold temporary files for example cache PID or session files for intermediate processing the vendor directory this directory contains the assets needed by third party gems for your application you probably won't use this directory much as many of the gems you are using are managed by bundle the bundle command is used to install and update gems by your application but two other important files are the gem file and the gem file dot lock these files allow you to say which dependencies are needed in your application these files are used by the bundler gem which again is used to install and update gems the rake file this file is used to locate and load tasks that can be run from the command line and finally the readme this file is used to tell other developers what your application does how it works you can think of this file as an instruction manual for your application alright so in the next video we're gonna go through and set up the MVC setup for our application
Info
Channel: Mackenzie Child
Views: 38,072
Rating: undefined out of 5
Keywords: Intro to Rails, Ruby on Rails, Ruby, Rails, Ruby 2, Rails 4, History of Rails, Introduction to Rails, Introduction to Ruby on Rails, Rails Basics, Ruby Basics, Web Application, Mackenzie Child, Mackenzie Childs
Id: fP64Wvz13AM
Channel Id: undefined
Length: 9min 9sec (549 seconds)
Published: Sun Sep 06 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.