Apportez votre aide…
Ceci est une ancienne révision du document !
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. Les versions concernées par cette documentation sont celles de Ubuntu Trusty Rails 3.2, et de Ubuntu Xenial Rails 4.2.
→ fournir une capture d'ecran de ror.
Pré-requis
- Disposer des droits d'administration.
- Disposer d'une connexion à Internet configurée et activée.
Installation
Pour installer ce logiciel, il suffit d'installer le paquet Rails , qui installera en même temps toutes les dépendances necessaires dont le langage Ruby et les fonctionnalités SQLite3.
Configuration
La configuration de Rails s'effectue automatiquement pour chaque application créée dans son dossier , voir ci-après.
Pour modifier le comportement de Rails lui-même, utilisez les options sur la ligne de commande :
man rails
que vous pouvez aussi obtenir avec juste la commande rails ou :
$ 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.
Utilisation
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 nécessaires (base sqlite3, mini serveur web).
$ 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
- Lancez ensuite le serveur Rails pour exécuter l'application weblog
$ cd $HOME/weblog $ 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)
- la base préconfigurée de l'application doit être activée
$ cd $HOME/weblog $ rake db:create
- l'exécution "rails server" s'effectue sans mentionner bin dans le chemin.
$ rails server
- Lancez le navigateur web à l'adresse localhost:3000, exemple avec midori
midori http://localhost:3000
Utilisations avancées
Les utilisateurs et programmeurs avancés pourront configurer Rails avec d'autres serveurs web comme Apache :
- modules Phusion Passenger Rails et Rack pour Apache libapache2-mod-passenger ,
ou d'autres moteurs de bases de données comme MySQL, PostgreSQL, ou via la connexion de bases JDBC. Lire soigneusement les guides de rubyonrails et l'API.
Désinstallation
Pour supprimer cette application, il suffit de supprimer son paquet. Selon la méthode choisie, la configuration globale de l'application est conservée ou supprimée. Les journaux du système, et les fichiers de préférence des utilisateurs dans leurs dossiers personnels sont toujours conservés.
Voir aussi
- (en) Rails
—- Correcteur : J5012.
Basé sur Getting Started with Rails par http://guides.rubyonrails.org/credits.html.
