rails
Manage Ruby on Rails applications
TLDR
Create a new rails project
Generate a scaffold for a model named Post, predefining the attributes title and body
Run migrations
List all routes
Start local server for current project on port 3000
Start local server for current project on a specified port
Open console to interact with application from command-line
Check current version of rails
SYNOPSIS
rails subcommand [options] [arguments]
Recommended invocation: bundle exec rails subcommand [options] [arguments]
PARAMETERS
--version
Displays the Ruby on Rails version being used.
--help, -h
Shows the help message for the rails command or a specific subcommand (e.g., rails help new).
--verbose, -v
Increases the verbosity of output for certain operations.
--no-color
Disables colored output from the rails command.
DESCRIPTION
The rails command is the primary command-line interface (CLI) for interacting with the Ruby on Rails web application framework. While not a native Linux utility, it's a crucial tool for developers building applications with Rails on Linux environments.
It provides functionalities ranging from creating new Rails projects (rails new), generating code (rails generate for models, controllers, etc.), managing the database (rails db for migrations, seeding), starting the development server (rails server), running tests (rails test), and entering the application console (rails console).
The rails command acts as a dispatcher for various subcommands, each with its own set of options and arguments, streamlining common development tasks and adhering to Rails' 'convention over configuration' philosophy.
CAVEATS
The rails command is part of the Ruby on Rails framework, not a core Linux utility. It requires a functional Ruby installation, RubyGems, and Bundler to be present on the system.
Most rails commands are context-dependent and must be run within a Rails application directory (except for rails new).
Its full functionality often depends on application-specific gems (managed by Bundler) and proper database configuration.
COMMON SUBCOMMANDS
The power of the rails command lies in its extensive subcommands, each designed for specific tasks. Some of the most frequently used include:
new: Creates a new Rails application.
server (s): Starts the development web server.
generate (g): Generates code for models, controllers, migrations, etc.
db: Manages database operations like migrations, seeding, and console access.
console (c): Opens an IRB session with your Rails application loaded.
test (t): Runs the application's test suite.
routes: Lists all defined application routes.
Each subcommand has its own specific options, which can be viewed using rails help <subcommand> (e.g., rails help new).
BUNDLE EXEC
It is best practice to prefix rails commands with bundle exec (e.g., bundle exec rails server). This ensures that the command runs using the specific gem versions defined in your application's Gemfile, preventing conflicts with other gem versions installed on your system.
HISTORY
Ruby on Rails was created by David Heinemeier Hansson (DHH) and open-sourced in July 2004. It quickly gained popularity for its developer-friendly approach, emphasizing 'Convention over Configuration' (CoC) and 'Don't Repeat Yourself' (DRY) principles.
The rails command-line interface has evolved alongside the framework, consolidating many tasks previously handled by Rake or custom scripts, becoming the central point for managing Rails applications.