- Create Ruby on Rails Project from Scratch, a beginner’s guide
- Installing Ruby on Rails on Mac OSX Platform
- Ruby on Rails Render Template & Pass Data to View
- Ruby on Rails Generate Controller & View via rails command
In this tutorial we will create Ruby on Rails Project. I hope you have ruby on rails installed on your machine, if not please check our previous tutorial on Installing Ruby on Rails. Lets see how we can create ruby on rails project.
First Create a directory to store all your rails projects. You can name it anything you want but i am using “Sites” folder to store all my rails project. Open Terminal on MAC or Command Prompt on Windows. I’m using MAC for rails project. Now navigate to Sites directory, which we just created. you dont have to create a directory for project, rails will create one for us.
Create Ruby on Rails Project
Type following command on terminal.
1 |
$ rails new first_project |
OR
if you wnat to use mysql as a database for your rails project. we can preconfigure rails project at create ruby on rails project command by passing an argument like below:
1 |
$ rails new first_project -d mysql |
We can also change configuration of database for rails project but above command will preconfigure that for us. By default rails uses SQLite. So make sure we are using -d mysql option as long as we use mysql database. when we issue one of above command it will create ruby on rails project by creating a folder named first_project. If you check that directory you will find bunch of files and directories that is created by rails command.
If we delete first_project directory, our rails application will be gone.
Accessing Project
Navigate to project directory, for me its first_project and i am already on that directory. In order to see our project we have to launch web server. Now we are not using apache but we are using one which comes with rails which is WEBrick and to launch WEBrick type following command on terminal:
1 |
rails server |
As soon as you issue above command you will see some messages like below:
Note: To stop rails server command is given to us in startup server screen which is Ctrl-C. so don’t close terminal. just leave it open and minimise it.
Now as you can see in those messages our WEBrick is running on port 3000 but how do we get there. Yes i guess you are right! Browser is the key to access localhost’s 3000 port. open your favourite browser and type url http://localhost:3000 and a rails screen will be displayed like below:
This is the rails project start up page. this shows our rails server is running perfectly. if we stop rails server and refresh page, it won’t show this page and gives error. In next tutorial we will create our first page of rails project.
I hope you like this tutorial.for more updates visit & like our FB Page.
Pingback: Ruby on Rails Generate Controller & View via command - Coderiddles