Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente | ||
| rubyonrails [Le 16/07/2017, 23:10] J5012 recyclage et corrections, nettoyage | rubyonrails [Le 31/08/2022, 23:32] (Version actuelle) moths-art Passage de http à https sur les liens externes (détecté et corrigé via le bot wiki-corrector (https://forum.ubuntu-fr.org/viewtopic.php?id=2067892) | ||
|---|---|---|---|
| Ligne 5: | Ligne 5: | ||
| ====== Rails (ou Ruby on Rails dit aussi RoR) ====== | ====== Rails (ou Ruby on Rails dit aussi RoR) ====== | ||
| - | Rails est un cadriciel libre orienté dans le développement d'applications web, et développé lui-même dans le langage [[:ruby|Ruby]]. Les versions concernées par cette documentation sont celles de Ubuntu Trusty Rails 3.2, et de Ubuntu Xenial Rails 4.2. | + | Rails est un cadriciel libre orienté dans le développement d'applications web, et développé lui-même dans le langage [[:ruby|Ruby]]. Les versions concernées par cette documentation sont celles de Ubuntu 14.04 Rails 3.2, et de Ubuntu 16.04 Rails 4.2. | 
| - | + | ||
| - | → fournir une capture d'ecran de ror. | + | |
| ===== Pré-requis ===== | ===== Pré-requis ===== | ||
| Ligne 16: | Ligne 13: | ||
| ===== Installation ===== | ===== Installation ===== | ||
| - | Pour installer ce logiciel, il suffit d'[[:tutoriel:comment_installer_un_paquet|installer le paquet]] **[[apt>rails|Rails]]** , qui installera en même temps toutes les dépendances necessaires dont le langage [[:ruby|Ruby]] et les fonctionnalités SQLite3. | + | Pour installer ce logiciel, il suffit d'[[:tutoriel:comment_installer_un_paquet|installer le paquet]] **[[apt>rails|Rails]]**, qui installera en même temps toutes les dépendances necessaires dont le langage [[:ruby|Ruby]] et les fonctionnalités SQLite3. | 
| ===== Configuration ===== | ===== Configuration ===== | ||
| Ligne 25: | Ligne 22: | ||
| <code>man rails </code> | <code>man rails </code> | ||
| + | que vous pouvez aussi obtenir avec juste la commande __rails__ ou : | ||
| + | <code bash> | ||
| + | rails new -h | ||
| + | Usage: | ||
| + | rails new APP_PATH [options] | ||
| + | |||
| + | Options: | ||
| + | -r, [--ruby=PATH]  # Path to the Ruby binary of your choice | ||
| + | # Default: /usr/bin/ruby | ||
| + | -m, [--template=TEMPLATE]  # Path to some application template (can be a filesystem path or URL) | ||
| + | [--skip-gemfile], [--no-skip-gemfile]  # Don't create a Gemfile | ||
| + | -B, [--skip-bundle], [--no-skip-bundle]  # Don't run bundle install | ||
| + | -G, [--skip-git], [--no-skip-git]  # Skip .gitignore file | ||
| + | [--skip-keeps], [--no-skip-keeps]  # Skip source control .keep files | ||
| + | -O, [--skip-active-record], [--no-skip-active-record]  # Skip Active Record files | ||
| + | -S, [--skip-sprockets], [--no-skip-sprockets]  # Skip Sprockets files | ||
| + | [--skip-spring], [--no-skip-spring]  # Don't install Spring application preloader | ||
| + | -d, [--database=DATABASE]  # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc) | ||
| + | # Default: sqlite3 | ||
| + | -j, [--javascript=JAVASCRIPT]  # Preconfigure for selected JavaScript library | ||
| + | # Default: jquery | ||
| + | -J, [--skip-javascript], [--no-skip-javascript]  # Skip JavaScript files | ||
| + | [--dev], [--no-dev]  # Setup the application with Gemfile pointing to your Rails checkout | ||
| + | [--edge], [--no-edge]  # Setup the application with Gemfile pointing to Rails repository | ||
| + | [--skip-turbolinks], [--no-skip-turbolinks]  # Skip turbolinks gem | ||
| + | -T, [--skip-test-unit], [--no-skip-test-unit]  # Skip Test::Unit files | ||
| + | [--rc=RC]  # Path to file containing extra configuration options for rails command | ||
| + | [--no-rc], [--no-no-rc]  # Skip loading of extra configuration options from .railsrc file | ||
| + | |||
| + | Runtime options: | ||
| + | -f, [--force]  # Overwrite files that already exist | ||
| + | -p, [--pretend], [--no-pretend]  # Run but do not make any changes | ||
| + | -q, [--quiet], [--no-quiet]  # Suppress status output | ||
| + | -s, [--skip], [--no-skip]  # Skip files that already exist | ||
| + | |||
| + | Rails options: | ||
| + | -h, [--help], [--no-help]  # Show this help message and quit | ||
| + | -v, [--version], [--no-version]  # Show Rails version number and quit | ||
| + | |||
| + | Description: | ||
| + | The 'rails new' command creates a new Rails application with a default | ||
| + | directory structure and configuration at the path you specify. | ||
| + | |||
| + | You can specify extra command-line arguments to be used every time | ||
| + | 'rails new' runs in the .railsrc configuration file in your home directory. | ||
| + | |||
| + | Note that the arguments specified in the .railsrc file don't affect the | ||
| + | defaults values shown above in this help message. | ||
| + | |||
| + | Example: | ||
| + | rails new ~/Code/Ruby/weblog | ||
| + | |||
| + | This generates a skeletal Rails installation in ~/Code/Ruby/weblog. | ||
| + | See the README in the newly created application to get going. | ||
| + | </code> | ||
| ===== Utilisation ===== | ===== Utilisation ===== | ||
| ==== Créez votre première application Rails (Hello, Rails !) ==== | ==== Créez votre première application Rails (Hello, Rails !) ==== | ||
| - | * Générez le squelette de l'application : cette commande créera un dossier nommé __weblog__ dans votre dossier personnel, et auto-configurera toutes les fonctionnalités necessaires (base sqlite3, mini serveur web). | + | * Générez le squelette de l'application : cette commande créera un dossier nommé __weblog__ dans votre dossier personnel, et auto-configurera toutes les fonctionnalités nécessaires (base sqlite3, mini serveur web). | 
| - | <code>rails new $HOME/weblog</code> | + | <code bash> | 
| + | rails new $HOME/weblog | ||
| + | create  | ||
| + | create  README.rdoc | ||
| + | create  Rakefile | ||
| + | create  config.ru | ||
| + | create  .gitignore | ||
| + | create  Gemfile | ||
| + | create  app | ||
| + | create  app/assets/javascripts/application.js | ||
| + | create  app/assets/stylesheets/application.css | ||
| + | create  app/controllers/application_controller.rb | ||
| + | create  app/helpers/application_helper.rb | ||
| + | create  app/views/layouts/application.html.erb | ||
| + | create  app/assets/images/.keep | ||
| + | create  app/mailers/.keep | ||
| + | create  app/models/.keep | ||
| + | create  app/controllers/concerns/.keep | ||
| + | create  app/models/concerns/.keep | ||
| + | create  bin | ||
| + | create  bin/bundle | ||
| + | create  bin/rails | ||
| + | create  bin/rake | ||
| + | create  bin/setup | ||
| + | create  config | ||
| + | create  config/routes.rb | ||
| + | create  config/application.rb | ||
| + | create  config/environment.rb | ||
| + | create  config/secrets.yml | ||
| + | create  config/environments | ||
| + | create  config/environments/development.rb | ||
| + | create  config/environments/production.rb | ||
| + | create  config/environments/test.rb | ||
| + | create  config/initializers | ||
| + | create  config/initializers/assets.rb | ||
| + | create  config/initializers/backtrace_silencers.rb | ||
| + | create  config/initializers/cookies_serializer.rb | ||
| + | create  config/initializers/filter_parameter_logging.rb | ||
| + | create  config/initializers/inflections.rb | ||
| + | create  config/initializers/mime_types.rb | ||
| + | create  config/initializers/session_store.rb | ||
| + | create  config/initializers/wrap_parameters.rb | ||
| + | create  config/locales | ||
| + | create  config/locales/en.yml | ||
| + | create  config/boot.rb | ||
| + | create  config/database.yml | ||
| + | create  db | ||
| + | create  db/seeds.rb | ||
| + | create  lib | ||
| + | create  lib/tasks | ||
| + | create  lib/tasks/.keep | ||
| + | create  lib/assets | ||
| + | create  lib/assets/.keep | ||
| + | create  log | ||
| + | create  log/.keep | ||
| + | create  public | ||
| + | create  public/404.html | ||
| + | create  public/422.html | ||
| + | create  public/500.html | ||
| + | create  public/favicon.ico | ||
| + | create  public/robots.txt | ||
| + | create  test/fixtures | ||
| + | create  test/fixtures/.keep | ||
| + | create  test/controllers | ||
| + | create  test/controllers/.keep | ||
| + | create  test/mailers | ||
| + | create  test/mailers/.keep | ||
| + | create  test/models | ||
| + | create  test/models/.keep | ||
| + | create  test/helpers | ||
| + | create  test/helpers/.keep | ||
| + | create  test/integration | ||
| + | create  test/integration/.keep | ||
| + | create  test/test_helper.rb | ||
| + | create  tmp/cache | ||
| + | create  tmp/cache/assets | ||
| + | create  vendor/assets/javascripts | ||
| + | create  vendor/assets/javascripts/.keep | ||
| + | create  vendor/assets/stylesheets | ||
| + | create  vendor/assets/stylesheets/.keep | ||
| + | run  bundle install --local | ||
| + | Resolving dependencies... | ||
| + | Using rake 10.5.0 | ||
| + | Using i18n 0.7.0 | ||
| + | Using json 1.8.3 | ||
| + | Using minitest 5.8.4 | ||
| + | Using thread_safe 0.3.5 | ||
| + | Using builder 3.2.2 | ||
| + | Using erubis 2.7.0 | ||
| + | Using nokogiri 1.6.7.2 | ||
| + | Using rack 1.6.4 | ||
| + | Using mime-types 2.6.1 | ||
| + | Using arel 6.0.3 | ||
| + | Using debug_inspector 0.0.2 | ||
| + | Using bundler 1.11.2 | ||
| + | Using columnize 0.9.0 | ||
| + | Using coffee-script-source 1.9.1.1 | ||
| + | Using execjs 2.6.0 | ||
| + | Using thor 0.19.1 | ||
| + | Using multi_json 1.11.2 | ||
| + | Using rdoc 4.2.1 | ||
| + | Using sass 3.4.21 | ||
| + | Using tilt 2.0.1 | ||
| + | Using spring 1.3.6 | ||
| + | Using sqlite3 1.3.11 | ||
| + | Using tzinfo 1.2.2 | ||
| + | Using loofah 2.0.3 | ||
| + | Using rack-test 0.6.3 | ||
| + | Using sprockets 3.3.0 | ||
| + | Using mail 2.6.3 | ||
| + | Using binding_of_caller 0.7.2 | ||
| + | Using byebug 5.0.0 | ||
| + | Using coffee-script 2.4.1 | ||
| + | Using uglifier 2.7.2 | ||
| + | Using sdoc 0.4.1 | ||
| + | Using activesupport 4.2.6 | ||
| + | Using rails-html-sanitizer 1.0.3 | ||
| + | Using rails-deprecated_sanitizer 1.0.3 | ||
| + | Using globalid 0.3.6 | ||
| + | Using activemodel 4.2.6 | ||
| + | Using jbuilder 2.3.1 | ||
| + | Using rails-dom-testing 1.0.6 | ||
| + | Using activejob 4.2.6 | ||
| + | Using activerecord 4.2.6 | ||
| + | Using actionview 4.2.6 | ||
| + | Using actionpack 4.2.6 | ||
| + | Using actionmailer 4.2.6 | ||
| + | Using railties 4.2.6 | ||
| + | Using sprockets-rails 2.3.2 | ||
| + | Using coffee-rails 4.1.0 | ||
| + | Using jquery-rails 4.0.5 | ||
| + | Using rails 4.2.6 | ||
| + | Using sass-rails 5.0.4 | ||
| + | Using web-console 2.2.1 | ||
| + | Using turbolinks 2.5.3 | ||
| + | Bundle complete! 12 Gemfile dependencies, 53 gems now installed. | ||
| + | Use `bundle show [gemname]` to see where a bundled gem is installed. | ||
| + | run  bundle exec spring binstub --all | ||
| + | * bin/rake: spring inserted | ||
| + | * bin/rails: spring inserted | ||
| + | </code> | ||
| * Lancez ensuite le serveur Rails pour exécuter l'application __weblog__ | * Lancez ensuite le serveur Rails pour exécuter l'application __weblog__ | ||
| - | <code>cd $HOME/weblog | + | <code bash>cd $HOME/weblog | 
| bin/rails server | bin/rails server | ||
| + | => Booting WEBrick | ||
| + | => Rails 4.2.6 application starting in development on http://localhost:3000 | ||
| + | => Run `rails server -h` for more startup options | ||
| + | => Ctrl-C to shutdown server | ||
| + | [2017-07-17 01:28:37] INFO WEBrick 1.3.1 | ||
| + | [2017-07-17 01:28:37] INFO ruby 2.3.1 (2016-04-26) [x86_64-linux-gnu] | ||
| + | [2017-07-17 01:28:37] INFO WEBrick::HTTPServer#start: pid=1849 port=3000 | ||
| + | |||
| + | |||
| + | Started GET "/" for 127.0.0.1 at 2017-07-17 01:34:32 -1000 | ||
| + | Processing by Rails::WelcomeController#index as HTML | ||
| + | Rendered /usr/lib/ruby/vendor_ruby/rails/templates/rails/welcome/index.html.erb (0.0ms) | ||
| + | Completed 200 OK in 1ms (Views: 0.7ms | ActiveRecord: 0.0ms) | ||
| </code> | </code> | ||
| - | <note>Dans la version de Ubuntu Trusty Rails 3.2, l'exécution "rails server" s'effectue de facon globale et non dans le dossier de l'application. | + | <note>Dans la version de Ubuntu 14.04 Rails 3.2 : | 
| + | * la base préconfigurée de l'application doit être activée | ||
| + | <code bash>cd $HOME/weblog | ||
| + | rake db:create</code> | ||
| + | * l'exécution "rails server" s'effectue sans mentionner bin dans le chemin. | ||
| <code>rails server</code> | <code>rails server</code> | ||
| </note> | </note> | ||
| - | * Lancez le navigateur web à l'adresse localhost:3000 | + | * Lancez le navigateur web à l'adresse localhost:3000, exemple avec __midori__ | 
| - | <code>firefox http://localhost:3000</code> | + | <code>midori http://localhost:3000</code> | 
| - | → fournir une capture d'ecran de Hello Rails | + | {{::midori_ror_new_weblog_capture_2017-07-17_01-35-55.jpg?direct&300|midori localhost:3000}} | 
| + | ==== Utilisations avancées ==== | ||
| + | |||
| + | Les utilisateurs et programmeurs avancés pourront configurer Rails avec d'autres serveurs web comme Apache : | ||
| + | * modules [[https://www.phusionpassenger.com/|Phusion Passenger]] Rails et Rack pour Apache **[[apt>libapache2-mod-passenger]]** , | ||
| + | ou d'autres moteurs de bases de données comme MySQL, PostgreSQL, ou via la connexion de bases JDBC. Lire soigneusement [[https://guides.rubyonrails.org/|les guides de rubyonrails]] et [[http://api.rubyonrails.org/|l'API]]. | ||
| ===== Désinstallation ===== | ===== Désinstallation ===== | ||
| Ligne 49: | Ligne 263: | ||
| * **(en)** [[http://rubyonrails.org|Rails]] | * **(en)** [[http://rubyonrails.org|Rails]] | ||
| - | * **(fr)** [[https://fr.wikipedia.org/wiki/Ruby_on_Rails|Ruby on Rails sur Wikipédia]] | + | * **(fr)** [[wpfr>Ruby_on_Rails|Ruby on Rails sur Wikipédia]] | 
| * **(fr)** [[http://railspremierspas.humancoders.com|Vos premiers pas en Ruby on Rails]] | * **(fr)** [[http://railspremierspas.humancoders.com|Vos premiers pas en Ruby on Rails]] | ||
| Ligne 55: | Ligne 269: | ||
| //Correcteur : [[utilisateurs:j5012|J5012]].// | //Correcteur : [[utilisateurs:j5012|J5012]].// | ||
| - | //Basé sur [[http://guides.rubyonrails.org/getting_started.html|Getting Started with Rails]] par [[http://guides.rubyonrails.org/credits.html]].// | + | //Basé sur [[https://guides.rubyonrails.org/getting_started.html|Getting Started with Rails]] par [[https://guides.rubyonrails.org/credits.html]].// |