Skip to content

Latest commit

 

History

History
191 lines (146 loc) · 5.61 KB

File metadata and controls

191 lines (146 loc) · 5.61 KB
title excerpt updated
Installer Rails sur votre hébergement web POWER
Découvrez comment installer Rails sur votre hébergement web POWER
2021-02-04

Objectif

Vous avez souscrit à un hébergement web POWER Ruby et vous voulez y déployer Rails{.external}, le framework de développement d'applications web en Ruby.

Découvrez comment installer Rails sur votre hébergement web POWER

Prérequis

Si vous n'êtes pas encore familier avec l'utilisation de votre hébergement web POWER, nous vous conseillons de consulter notre guide « Premiers pas avec un hébergement web POWER » avant de poursuivre la lecture de ce guide.

En pratique

Supposons que vous avez la configuration normale pour un hébergement web POWER :

  • Moteur : ruby 2.6
  • Point d'entrée : config.ru
  • Dossier racine : www

[!primary]

Vous pouvez appeler l'API OVHcloud pour visualiser la configuration active.

Accédez via SSH à votre hébergement web POWER.

Supprimez le dossier racine pour l'initialiser avec Rails. N'oubliez pas d'exporter votre gempath ou l'installation du bundle va échouer :

rm -rf www
gem env gempath
export GEM_HOME=$(gem env gempath | cut -d ':' -f1)
rails new www
cd www/
rails  webpacker:install

Déclarez votre nom de domaine sur liste blanche dans www/config/environments/development.rb :

Rails.application.configure do
  # Whitelist one hostname
  config.hosts << "your-domain.ovh"

Désactivez la vérification check_yarn_integrity dans la partie development de www/config/webpacker.yml :

development:
  <<: *default
  compile: true

  # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
  check_yarn_integrity: false

Redémarrez votre instance, votre Rails sera alors en ligne.

Rails{.thumbnail}

Générez maintenant un Hello World avec Rails.

export SPRING_SERVER_COMMAND="$HOME/www/bin/spring server"
rails generate controller demo index

Et créez un fichier app/views/demo/index.html.erb.

vim app/views/demo/index.html.erb
<h1>Hello World</h1>
<p>Hello World from Rails</p>

Ensuite construisez le Hello World.

./bin/webpack

Après redémarrage de votre instance, vous pourrez visualiser votre page dans https://<votre-nom-de-domaine>/demo/index.html

Rails{.thumbnail}

Sortie de la console :

~ $ rm -rf www

~ $ gem env gempath
/homez.41/powerlp/.gem/ruby/2.6.0:/usr/local/ruby2.6/lib/ruby/gems/2.6.0

~ $ rails new www
      create
      create  README.md
      create  Rakefile
      create  .ruby-version
[...]
Fetching webpacker 4.3.0
Installing webpacker 4.3.0
Bundle complete! 17 Gemfile dependencies, 75 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
         run  bundle binstubs bundler
[...]   
Installing all JavaScript dependencies [4.3.0]
         run  yarn add @rails/[email protected] from "."
yarn add v1.22.10
[...]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
├─ [email protected]
└─ [email protected]
Done in 6.19s.
Webpacker successfully installed 🎉 🍰

~ $ cd www/

~/www $ rails  webpacker:install
   identical  config/webpacker.yml
Copying webpack core config
       exist  config/webpack
   identical  config/webpack/development.js
   identical  config/webpack/environment.js
   identical  config/webpack/production.js
   identical  config/webpack/test.js
[...]
info Direct dependencies
└─ [email protected]
info All dependencies
└─ [email protected]
Done in 3.81s.
Webpacker successfully installed 🎉 🍰

~/www $ export SPRING_SERVER_COMMAND="$HOME/www/bin/spring server"

~/www $ rails generate controller demo index
Running via Spring preloader in process 11410
      create  app/controllers/demo_controller.rb
       route  get 'demo/index'
      invoke  erb
      create    app/views/demo
      create    app/views/demo/index.html.erb
      invoke  test_unit
      create    test/controllers/demo_controller_test.rb
      invoke  helper
      create    app/helpers/demo_helper.rb
      invoke    test_unit
      invoke  assets
      invoke    scss
      create      app/assets/stylesheets/demo.scss

~/www $ vim app/views/demo/index.html.erb
&lt;h1>Hello World&lt;/h1>
&lt;p>Hello World from Rails&lt;/p>

~/www $ ./bin/webpack
Hash: 15d1bb7b54cf6326b9ba
Version: webpack 4.44.2
Time: 1102ms
[...]

~/www $ mkdir -p tmp

~/www $ touch tmp/restart.txt

Plus d'information sur Rails

Pour plus d'informations sur Rails, n'hésitez pas à consulter la documentation officielle sur https://guides.rubyonrails.org/.

Aller plus loin

Échangez avec notre communauté d'utilisateurs.

Venez sur Discord sur notre room web-hosting-power pour discuter avec les autres utilisateurs du lab et avec l'équipe POWER Web Hosting.