Code Monkey home page Code Monkey logo

feliverse / hellorails Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 27 KB

As you know by now, we have a clear path from the browser to the routes file to the Controller action, which can pull data from the database through the Model and create an instance variable that is then sent to the View to be displayed to the user.

License: MIT License

Ruby 75.63% JavaScript 3.97% CSS 2.27% HTML 18.12%
first-project hello-world postgresql ruby-on-rails

hellorails's Introduction

Hello Rails app

Learning objectives

  • Install Ruby on Rails framework.
  • Use RubyGems as a software package system.

Estimated time: 1.5h

Exercise

As you know by now, we have a clear path from the browser to the routes file to the Controller action, which can pull data from the database through the Model and create an instance variable that is then sent to the View to be displayed to the user.

Let's put this into practice by creating our very own Rails 'Hello World!' project!

IMPORTANT NOTE: Read all instructions before you start this exercise.

Instructions

  • Create a new app called 'hellorails'.
  • Initialize your project with Git.
  • Make sure that your project has Postgres database set up.
  • Run rails server and visit http://localhost:3000/ in your browser!

Play with your first Rails website

After checking to make sure your Rails project is being served to the browser (http://localhost:3000/), there are a few things that need to be changed in order to set the display to let us view what we want. Do not worry if you do not understand everything - you will learn the technical explanation for what is happening in the upcoming lessons.

  • Let's use Rails' generators (known as scaffolding) to automagically make the files we need. For this you will do rails generate controller Pages hello in your shell, look at the example:
    $> rails generate controller Pages hello
    
        create  app/controllers/pages_controller.rb
         route  get 'pages/hello'
        invoke  erb
        create    app/views/pages
        create    app/views/pages/hello.html.erb
        invoke  test_unit
        create    test/controllers/pages_controller_test.rb
        invoke  helper
        create    app/helpers/pages_helper.rb
        invoke    test_unit
    
  • Looking at the output of the command you will see all the generated things, but for now you only need to focus on one app/views/pages/hello.html.erb. You will put your HTML in this one.
  • Open the file app/views/pages/hello.html.erb and add an h1 element saying "Hello world".
  • Open http://localhost:3000/pages/hello in your browser. You should see your "Hello world" message.
  • In config/routes.rb replace get 'pages#hello' with root 'pages#hello'
  • Revisit http://localhost:3000/ and see your changes in action. Now your "Hello world" page should be displayed as the main page.
  • Push all your changes to GitHub.

Submit your exercise

Read this FAQ for a reminder on how to submit your exercise. Now go to your Student Dashboard and submit your exercise. Paste a link to your GitHub repository.


If you spot any bugs or issues in this activity, you can open an issue with your proposed change.

hellorails's People

Contributors

feliverse avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.