This blog is about creating a first Rails web application.
Before proceeding, you need to install sqlite.
Summary of Steps
- Install sqlite
- Install nodejs
- Create hellorails
- Running hellorails
To install sqlite, run the follow commands:
$ sudo apt-get install sqlite3 $ sudo apt-get install libsqlite3-dev
Note: We have to install libsqlite3-dev because we want to use add sqlite support to Rails via gem.
After sqlite is installed, we can add sqlite support to Rails by running the following command.
$ sudo gem install sqlite3 -v '1.3.11'
Rails do not a built-in web server. It relies on other infrastructure to run. Here, I decide to install nodejs as I am intending to do some other nodejs development later on as well.
$ sudo apt-get install nodejs $ sudo apt-get install npm
After all the setup is done, we can start to create our hellorails application by running the following command:
sudo rails new ./hellorails
After the application is created, navigate into the directory.
You can run the application by running the following command:
$ rails server
Note: This command will start a web server listening on localhost on port 3000. What this means, is that you can only access the web application on your local machine. To allow other machines to access the web application on port 3000, you need to make the web server listen to the IP address of 0.0.0.0. This can be done by running:
$ rails server -b 0.0.0.0
An alternative to adding the parameter is edit boot.rb file in the config folder.