How to create a Rails 4.1 application from zero

1 de noviembre, 2015 @ 01:32 — 0 comentarios

In this guide we explain how to create and deploy a Ruby on Rails 4.1 application.

Note that you require SSH access and access to compilers.

1 - Define the app from the Hosting Panel

1 - Access your Hosting Panel

Just follow instruccions of How to access your Hosting Panel.

2 - Click on Ruby Applications

Look for and click on Ruby Applications icon.

hosting-programming-advanced

3 - Define the app

Fill in the form and make sure you choose Ruby Hai or Ruby Kon stack:

ruby-create-1

Once you submit the form you we'll see the app creation result. Remember the application directory as it's important in the next steps.

ruby-create-2

2 - Install Rails and Bundler gems

Install the 4.1 version on Ruby on Rails:

gem install rails -v 4.1

When installing Rails 4.1 Bundler should have been installed, but if for some reason tBundler has not been installed, run:

gem install bundler

3 - Create the application

In the first step you have defined the application, therefore you should known the it's named and directory.

Suppose that the application's name is myapp and the directory is /home/username/ruby/myapp, run the following to create the application:

cd ruby
rm -fr myapp
rails new myapp

4 - Edit the Gemfile

Open the default Gemfile:

cd ruby/myapp
nano Gemfile

And replace the following line:

#gem 'therubyracer', platforms: :ruby

With this one:

gem 'therubyracer', platforms: :ruby

Note: Yes, we have just uncommented the line.

5 - Install dependencies

Now it's time to install the application dependecies:

cd ruby/myapp
bundler install

6 - Restart application

cd ruby/myapp
touch tmp/restart.txt

7 - Verify installation

Access your website to verify that previous steps are correct. You should see a Rails error message such as:

ruby-deploy-rails4-1

8 - Create a Welcome page

Just run:

rails generate controller welcome index

9 - Customize the Welcome message

Open the view file created in the previous step:

nano app/views/welcome/index.html.erb

Delete all it's content and add:

<h1>Hola, Rails!</h1>

10 - Configure routes

We want to show the previous message in the root of the domain. In order to do that, open the config/routes.rb file:

nano config/routes.rb

And replace this line:

#root 'welcome#index'

With:

root 'welcome#index'

11 - Restart application

touch tmp/restart.txt

12 - Access your website

ruby-deploy-rails4-3

Etiquetas: