Creating a simple ruby app

Note: For linux users.

1) Open your terminal.

$ rails new appname

2)Go to application directory

$ cd appname

3)If you list the content(using ” $ ls ” ),you will seea number of autogenerated files and folders which makes a basic structure of rails.

File/Folder name Purpose
app/ Contains the controllers, models, views, helpers, mailers and assets for your application.
bin/ Contains the rails script that starts your app and can contain other scripts you use to setup, deploy or run your application.
config/ Configure your application’s routes, database,e.t.c. Rack configuration for Rack based servers used to start the application.
db/ Contains your current database schema, as well as the database migrations.
These files allow you to specify what gem dependencies are needed for your Rails application. These files are used by the Bundler gem.
lib/ Extended modules for your application.
log/ Application log files.
public/  Contains static files and compiled assets.
Rakefile This file locates and loads tasks that can be run from the command line.
README.rdoc This is a brief instruction manual for your application. You should edit this file to tell others what your application does, how to set it up, and so on.
test/ Unit tests, fixtures, and other test apparatus.
tmp/ Temporary files (like cache, pid, and session files).
vendor/ A place for all third-party code.

4) Now check if your application is running correctly

$ rails s

(Open a browser window and navigate to http://localhost:3000. You should see the Rails default page)


 5) Next we,have to create a controller(A controller’s purpose is to receive specific requests for the application).Here we create a controller with name “welcome” and action “index”.

$ rails generate controller welcome index

6)You will see a number of files along with a route automatically created.

7) To display some text on your application page,open app/views/welcome/index.html.erb file in your text editor and type the text.For example,

<h1>Hello rails</h1>

8) Now that we have made the controller and view, we need to tell Rails when we want the text to show up(ie,fix routes for your homepage).

Open the file config/routes.rb in your editor.Uncomment the line beginning with ‘root’.

9) Launch rails server and navigate to http://localhost:3000 in your browser. You’ll see the text you put into app/views/welcome/index.html.erb , indicating that this new route is indeed going to WelcomeController‘s index action and is rendering the view correctly.




Ruby on Rails-Installation

Note:The following instructions are for linux users.There are other ways to install ruby ie,with rbenv ,with rvm,e.t.c.This is way too simple.

1)First update your package manager

$ sudo apt-get update

2)Make sure that ruby is installed on your system.You can install ruby by

$ sudo apt-get install ruby

and check the version by:

$ ruby -v

3)Next step is to install bundler(bundler works as ruby gem manager.gems are like ruby libraries)

$ gem install bundler

4)Next,we will install Rails(the ruby framework)

$ gem install rails

and check for version

$ rails -v