Coder Social home page Coder Social logo

hellorailsapp's Introduction

HelloRailsApp

Let's create an entire usable project with one simple line:

  • rails new Project [Sets SQLite3 as the default DB]

But first,

Let's check to make sure that our system has the proper prerequisites installed. These include:

  • Ruby (ruby --version)
  • SQLite3 (sqlite3 --version) SQLite3 Website [And we can use postgreSQL instead as well]

And also check if rails is installed on our machine already by running:

  • rails --version

If not, let's install rails & then we will also choose postgreSQL as our default DB during the creation of our first app.

To install rails & check version:

  • gem install rails
  • and check again by running rails --version

To set postgresql as the default database instead of SQLite3

  • rails new ProjectName --database=postgresql

This will create a Rails application called ProjectName in a directory called ProjectName. Now go to

  • cd ProjectName

and install all the gem dependencies that are already mentioned in Gemfile using

  • bundle install

To Run/ Server the project:

  • rails server or,
  • bin/rails server or bin/rails s
  • For windows run ruby bin\rails server

This will start up Puma, a web server distributed with Rails by default. To see your application in action, visit http://localhost:3000/ in your browser! PS: we can press Ctrl-C to stop the server.

Play with your first Rails website

After checking to make sure our 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.

  • 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.

Rails Naming Convension

rails naming convention img
The default branch has been renamed!
hello-feature is now named main

If you have a local clone, you can update it by running the following commands.

git branch -m hello-feature main
git fetch origin
git branch -u origin/main main
git remote set-head origin -a

hellorailsapp's People

Contributors

porag-m06 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.