Other Pages

Expand All

creating_a_rails_application.step

img src: "img/Start_page.png", alt: "Screenshot of a Ruby on Rails default home page"

goals do
  goal "Create your new application"
  message "Let's get started! By the end of this step, we'll have a brand-new Rails app."
end

steps do

  tip "If you have _any_ problems, contact a TA immediately."

  step do
    message <<-MARKDOWN
    Make sure you have exited irb. If you haven't, your screen will say `irb(main):001:0>`. Leave irb by typing `exit`.

    If you are using a virtual machine, make sure you are in it before continuing.
    If you are in the virtual machine:

    * Your command line prompt should be `RailsBridge-VM:/vagrant$`

    If you do not see that command prompt:

    * Check to see if it is running by typing `vagrant up`
    * Enter the virtual machine by typing `vagrant ssh`
    MARKDOWN

    cloud9_instruction
    
    message <<-MARKDOWN   
    * Your command prompt should look something like: `ec2-user:~/environment`

    Ask a TA if you need help.
    MARKDOWN
  end

  step do
    # NOTE: this is the place where we would add the app template ( -m ~/vm.rb )
    # if we wanted to do that instead of passing -b to every server invocation
    console "rails new suggestotron"
    message "`rails new` creates a new Rails project with the given name."
    message "In this case we told it to create a new project called `suggestotron`. We'll go into detail on exactly what it did shortly."
  end

  step do
    console "cd suggestotron"
    message '`cd` stands for "change directory".'
    message "`cd suggestotron` makes suggestotron our current directory."
  end

  step do
    console "ls"
    message '`ls` stands for "list (stuff)".'
    message "It shows you the contents of the current folder."
  end

  step do
    message <<-MARKDOWN
Let's look at the structure of the whole project.

You can see the project directory when you're using Sublime Text or Cloud9. This is
convenient when you're going to edit several files and want to navigate quickly.

![Screenshot of Suggestotron project folder tree in Cloud9](img/cloud9_project_folder.png)

Open the suggestotron folder as a project in Sublime Text by clicking the
Project menu and selecting "Add Folder to Project":

![Sublime Text Project menu screenshot](img/sublime_add_folder_to_project.png)

Select your `suggestotron` folder from the file picker that opens. If everything works out Sublime should show the directories of your app in a tree structure on the left:

![Screenshot of Suggestotron project folder tree in Sublime Text](img/sublime_project_as_folder.png)
    MARKDOWN
  end

  message <<-MARKDOWN
  You can see that `rails new` created a lot of directories and
  files. The ones we want to focus on today are:
  MARKDOWN

  table border: "1", cellspacing: "0", cellpadding: "3", align: "center" do
    tr do
      th "File/Folder"
      th "Purpose"
    end

    tr do
      td "app/"
      td "Contains the controllers, models, and views for your application.  You will do most of your work here."
    end

    tr do
      td "config/"
      td "Configure your application's runtime rules, routes, database, and more."
    end

    tr do
      td "db/"
      td "Shows your current database schema, as well as the database migrations."
    end

    tr do
      td "public/"
      td "The only folder seen to the world as-is. If you put files in here, they will be served directly without any processing by Rails."
    end

    tr do
      td "app/assets/"
      td "This is where your images, JavaScript, stylesheets (CSS), and other static files should go. Modern rails apps use something called the Assets Pipeline, which combines all the JavaScript and CSS files in this directory into a single file for speediness."
    end
  end

  message "There is a lot more that `rails new` created. Probably enough to fill a book, so we're going to ignore them for now."
end

next_step "running_your_application_locally"