CINXE.COM

Contributing to Ruby on Rails — Ruby on Rails Guides

<!doctype html> <html dir="ltr" lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Contributing to Ruby on Rails — Ruby on Rails Guides</title> <link rel="stylesheet" type="text/css" href="stylesheets/style-74a32dfd0cef32332d4ee58c1c94ff69.css" data-turbo-track="reload"> <link rel="stylesheet" type="text/css" href="stylesheets/print-a87ee66d50ce96bb83ac082f1249fe3e.css" media="print"> <link rel="stylesheet" type="text/css" href="stylesheets/highlight-2794201d063bd2e4dbd0f0874c2a3f6f.css" data-turbo-track="reload"> <link rel="icon" href="images/favicon.ico" sizes="any"> <link rel="apple-touch-icon" href="images/icon.png"> <link rel="canonical" href="https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html"> <script src="javascripts/@hotwired--turbo-764f59c7edbeb902a9068c0340dd274e.js" data-turbo-track="reload"></script> <script src="javascripts/clipboard-8b7aed6f069f0cf58eeae353cd2f898b.js" data-turbo-track="reload"></script> <script src="javascripts/guides-751b87e159daf790ddf7e8e88ad8465a.js" data-turbo-track="reload"></script> <meta property="og:title" content="Contributing to Ruby on Rails — Ruby on Rails Guides" /> <meta name="description" content="This guide covers how you can become a part of the ongoing development of Ruby on Rails.After reading this guide, you will know: How to use GitHub to report issues. How to clone main and run the test suite. How to help resolve existing issues. How to contribute to the Ruby on Rails documentation. How to contribute to the Ruby on Rails code. Ruby on Rails is not &quot;someone else&#39;s framework&quot;. Over the years, thousands of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all to make Ruby on Rails better for everyone. Even if you don&#39;t feel up to writing code or documentation yet, there are various other ways that you can contribute, from reporting issues to testing patches.As mentioned in Rails&#39; README, everyone interacting in Rails and its sub-projects&#39; codebases, issue trackers, chat rooms, discussion boards, and mailing lists is expected to follow the Rails code of conduct." /> <meta property="og:description" content="This guide covers how you can become a part of the ongoing development of Ruby on Rails.After reading this guide, you will know: How to use GitHub to report issues. How to clone main and run the test suite. How to help resolve existing issues. How to contribute to the Ruby on Rails documentation. How to contribute to the Ruby on Rails code. Ruby on Rails is not &quot;someone else&#39;s framework&quot;. Over the years, thousands of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all to make Ruby on Rails better for everyone. Even if you don&#39;t feel up to writing code or documentation yet, there are various other ways that you can contribute, from reporting issues to testing patches.As mentioned in Rails&#39; README, everyone interacting in Rails and its sub-projects&#39; codebases, issue trackers, chat rooms, discussion boards, and mailing lists is expected to follow the Rails code of conduct." /> <meta property="og:locale" content="en_US" /> <meta property="og:site_name" content="Ruby on Rails Guides" /> <meta property="og:image" content="https://avatars.githubusercontent.com/u/4223" /> <meta property="og:type" content="website" /> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+Arabic:wght@100..900&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Heebo:wght@100..900&family=Noto+Sans+Arabic:wght@100..900&display=swap" rel="stylesheet"> <meta name="theme-color" content="#C81418"> </head> <body dir="ltr" class="guide no-js"> <script> document.body.classList.remove('no-js') </script> <a id="main-skip-link" href="#main" class="skip-link" data-turbo="false"> Skip to main content </a> <div id="mobile-navigation-bar"> <div class="wrapper"> <strong class="more-info-label">More at <a href="https://rubyonrails.org/">rubyonrails.org:</a> </strong> <button type="button" class="js-only red-button more-info-button" id="more-info" aria-controls="more-info-links" aria-expanded="false"> More Ruby on Rails </button> <ul id="more-info-links" class="more-info-links hidden"> <li class="more-info"><a href="https://rubyonrails.org/blog">Blog</a></li> <li class="more-info"><a href="https://guides.rubyonrails.org/">Guides</a></li> <li class="more-info"><a href="https://api.rubyonrails.org/">API</a></li> <li class="more-info"><a href="https://discuss.rubyonrails.org/">Forum</a></li> <li class="more-info"><a href="https://github.com/rails/rails">Contribute on GitHub</a></li> </ul> </div> </div> <header id="page-header"> <div class="wrapper clearfix"> <nav id="feature-nav"> <div class="header-logo"> <a href="index.html" title="Guides home for Edge Guides">Guides</a> <span id="version-switcher" class="js-only"> <label for="version-switcher-select">Version: <span class="visibly-hidden">pick from the list to go to that Rails version's guides</span></label> <select id="version-switcher-select" class="guides-version"> <option value="https://edgeguides.rubyonrails.org/" selected>Edge</option> <option value="https://guides.rubyonrails.org/v8.0/contributing_to_ruby_on_rails.html">8.0</option> <option value="https://guides.rubyonrails.org/v7.2/contributing_to_ruby_on_rails.html">7.2</option> <option value="https://guides.rubyonrails.org/v7.1/contributing_to_ruby_on_rails.html">7.1</option> <option value="https://guides.rubyonrails.org/v7.0/contributing_to_ruby_on_rails.html">7.0</option> <option value="https://guides.rubyonrails.org/v6.1/contributing_to_ruby_on_rails.html">6.1</option> <option value="https://guides.rubyonrails.org/v6.0/contributing_to_ruby_on_rails.html">6.0</option> <option value="https://guides.rubyonrails.org/v5.2/contributing_to_ruby_on_rails.html">5.2</option> <option value="https://guides.rubyonrails.org/v5.1/contributing_to_ruby_on_rails.html">5.1</option> <option value="https://guides.rubyonrails.org/v5.0/contributing_to_ruby_on_rails.html">5.0</option> <option value="https://guides.rubyonrails.org/v4.2/contributing_to_ruby_on_rails.html">4.2</option> <option value="https://guides.rubyonrails.org/v4.1/contributing_to_ruby_on_rails.html">4.1</option> <option value="https://guides.rubyonrails.org/v4.0/contributing_to_ruby_on_rails.html">4.0</option> <option value="https://guides.rubyonrails.org/v3.2/contributing_to_ruby_on_rails.html">3.2</option> <option value="https://guides.rubyonrails.org/v3.1/contributing_to_ruby_on_rails.html">3.1</option> <option value="https://guides.rubyonrails.org/v3.0/contributing_to_ruby_on_rails.html">3.0</option> <option value="https://guides.rubyonrails.org/v2.3/contributing_to_ruby_on_rails.html">2.3</option> </select> </span> </div> <ul class="nav"> <li><a class="nav-item" id="home_nav" href="https://rubyonrails.org/">Home</a></li> <li class="guides-index guides-index-large"> <a href="index.html" id="guides-menu-button" data-aria-controls="guides" data-aria-expanded="false" class="guides-index-item nav-item">Guides Index</a> <div id="guides" class="clearfix" style="display: none;"> <hr /> <dl class="guides-section-container"> <div class="guides-section"> <dt>Start Here</dt> <dd><a href="getting_started.html">Getting Started with Rails</a></dd> <dd><a href="install_ruby_on_rails.html">Install Ruby on Rails</a></dd> </div> <div class="guides-section"> <dt>Models</dt> <dd><a href="active_record_basics.html">Active Record Basics</a></dd> <dd><a href="active_record_migrations.html">Active Record Migrations</a></dd> <dd><a href="active_record_validations.html">Active Record Validations</a></dd> <dd><a href="active_record_callbacks.html">Active Record Callbacks</a></dd> <dd><a href="association_basics.html">Active Record Associations</a></dd> <dd><a href="active_record_querying.html">Active Record Query Interface</a></dd> <dd><a href="active_model_basics.html">Active Model Basics</a></dd> </div> <div class="guides-section"> <dt>Views</dt> <dd><a href="action_view_overview.html">Action View Overview</a></dd> <dd><a href="layouts_and_rendering.html">Layouts and Rendering in Rails</a></dd> <dd><a href="action_view_helpers.html">Action View Helpers</a></dd> <dd><a href="form_helpers.html">Action View Form Helpers</a></dd> </div> <div class="guides-section"> <dt>Controllers</dt> <dd><a href="action_controller_overview.html">Action Controller Overview</a></dd> <dd><a href="action_controller_advanced_topics.html">Action Controller Advanced Topics</a></dd> <dd><a href="routing.html">Rails Routing from the Outside In</a></dd> </div> <div class="guides-section"> <dt>Other Components</dt> <dd><a href="active_support_core_extensions.html">Active Support Core Extensions</a></dd> <dd><a href="action_mailer_basics.html">Action Mailer Basics</a></dd> <dd><a href="action_mailbox_basics.html">Action Mailbox Basics</a></dd> <dd><a href="action_text_overview.html">Action Text Overview</a></dd> <dd><a href="active_job_basics.html">Active Job Basics</a></dd> <dd><a href="active_storage_overview.html">Active Storage Overview</a></dd> <dd><a href="action_cable_overview.html">Action Cable Overview</a></dd> </div> <div class="guides-section"> <dt>Digging Deeper</dt> <dd><a href="i18n.html">Rails Internationalization (I18n) API</a></dd> <dd><a href="testing.html">Testing Rails Applications</a></dd> <dd><a href="debugging_rails_applications.html">Debugging Rails Applications</a></dd> <dd><a href="configuring.html">Configuring Rails Applications</a></dd> <dd><a href="command_line.html">The Rails Command Line</a></dd> <dd><a href="asset_pipeline.html">The Asset Pipeline</a></dd> <dd><a href="working_with_javascript_in_rails.html">Working with JavaScript in Rails</a></dd> <dd><a href="autoloading_and_reloading_constants.html">Autoloading and Reloading</a></dd> <dd><a href="api_app.html">Using Rails for API-only Applications</a></dd> </div> <div class="guides-section"> <dt>Going to Production</dt> <dd><a href="tuning_performance_for_deployment.html">Tuning Performance for Deployment</a></dd> <dd><a href="caching_with_rails.html">Caching with Rails: An Overview</a></dd> <dd><a href="security.html">Securing Rails Applications</a></dd> <dd><a href="error_reporting.html">Error Reporting in Rails Applications</a></dd> </div> <div class="guides-section"> <dt>Advanced Active Record</dt> <dd><a href="active_record_multiple_databases.html">Multiple Databases</a></dd> <dd><a href="active_record_composite_primary_keys.html">Composite Primary Keys</a></dd> </div> <div class="guides-section"> <dt>Extending Rails</dt> <dd><a href="rails_on_rack.html">Rails on Rack</a></dd> <dd><a href="generators.html">Creating and Customizing Rails Generators &amp; Templates</a></dd> </div> <div class="guides-section"> <dt>Contributing</dt> <dd><a href="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</a></dd> <dd><a href="api_documentation_guidelines.html">API Documentation Guidelines</a></dd> <dd><a href="ruby_on_rails_guides_guidelines.html">Guides Guidelines</a></dd> <dd><a href="development_dependencies_install.html">Installing Rails Core Development Dependencies</a></dd> </div> <div class="guides-section"> <dt>Policies</dt> <dd><a href="maintenance_policy.html">Maintenance Policy</a></dd> </div> <div class="guides-section"> <dt>Release Notes</dt> <dd><a href="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</a></dd> <dd><a href="8_0_release_notes.html">Version 8.0 - November 2024</a></dd> <dd><a href="7_2_release_notes.html">Version 7.2 - August 2024</a></dd> <dd><a href="7_1_release_notes.html">Version 7.1 - October 2023</a></dd> <dd><a href="7_0_release_notes.html">Version 7.0 - December 2021</a></dd> <dd><a href="6_1_release_notes.html">Version 6.1 - December 2020</a></dd> <dd><a href="6_0_release_notes.html">Version 6.0 - August 2019</a></dd> <dd><a href="5_2_release_notes.html">Version 5.2 - April 2018</a></dd> <dd><a href="5_1_release_notes.html">Version 5.1 - April 2017</a></dd> <dd><a href="5_0_release_notes.html">Version 5.0 - June 2016</a></dd> <dd><a href="4_2_release_notes.html">Version 4.2 - December 2014</a></dd> <dd><a href="4_1_release_notes.html">Version 4.1 - April 2014</a></dd> <dd><a href="4_0_release_notes.html">Version 4.0 - June 2013</a></dd> <dd><a href="3_2_release_notes.html">Version 3.2 - January 2012</a></dd> <dd><a href="3_1_release_notes.html">Version 3.1 - August 2011</a></dd> <dd><a href="3_0_release_notes.html">Version 3.0 - August 2010</a></dd> <dd><a href="2_3_release_notes.html">Version 2.3 - March 2009</a></dd> <dd><a href="2_2_release_notes.html">Version 2.2 - November 2008</a></dd> </div> </dl> </div> </li> <li><a class="nav-item" href="contributing_to_ruby_on_rails.html">Contribute</a></li> <li class="guides-index guides-index-small js-only"> <label for="guides-selector"> Navigate to a guide: </label> <select id="guides-selector" class="guides-index-item nav-item"> <option value="index.html">Guides Index</option> <optgroup label="Start Here"> <option value="getting_started.html">Getting Started with Rails</option> <option value="install_ruby_on_rails.html">Install Ruby on Rails</option> </optgroup> <optgroup label="Models"> <option value="active_record_basics.html">Active Record Basics</option> <option value="active_record_migrations.html">Active Record Migrations</option> <option value="active_record_validations.html">Active Record Validations</option> <option value="active_record_callbacks.html">Active Record Callbacks</option> <option value="association_basics.html">Active Record Associations</option> <option value="active_record_querying.html">Active Record Query Interface</option> <option value="active_model_basics.html">Active Model Basics</option> </optgroup> <optgroup label="Views"> <option value="action_view_overview.html">Action View Overview</option> <option value="layouts_and_rendering.html">Layouts and Rendering in Rails</option> <option value="action_view_helpers.html">Action View Helpers</option> <option value="form_helpers.html">Action View Form Helpers</option> </optgroup> <optgroup label="Controllers"> <option value="action_controller_overview.html">Action Controller Overview</option> <option value="action_controller_advanced_topics.html">Action Controller Advanced Topics</option> <option value="routing.html">Rails Routing from the Outside In</option> </optgroup> <optgroup label="Other Components"> <option value="active_support_core_extensions.html">Active Support Core Extensions</option> <option value="action_mailer_basics.html">Action Mailer Basics</option> <option value="action_mailbox_basics.html">Action Mailbox Basics</option> <option value="action_text_overview.html">Action Text Overview</option> <option value="active_job_basics.html">Active Job Basics</option> <option value="active_storage_overview.html">Active Storage Overview</option> <option value="action_cable_overview.html">Action Cable Overview</option> </optgroup> <optgroup label="Digging Deeper"> <option value="i18n.html">Rails Internationalization (I18n) API</option> <option value="testing.html">Testing Rails Applications</option> <option value="debugging_rails_applications.html">Debugging Rails Applications</option> <option value="configuring.html">Configuring Rails Applications</option> <option value="command_line.html">The Rails Command Line</option> <option value="asset_pipeline.html">The Asset Pipeline</option> <option value="working_with_javascript_in_rails.html">Working with JavaScript in Rails</option> <option value="autoloading_and_reloading_constants.html">Autoloading and Reloading</option> <option value="api_app.html">Using Rails for API-only Applications</option> </optgroup> <optgroup label="Going to Production"> <option value="tuning_performance_for_deployment.html">Tuning Performance for Deployment</option> <option value="caching_with_rails.html">Caching with Rails: An Overview</option> <option value="security.html">Securing Rails Applications</option> <option value="error_reporting.html">Error Reporting in Rails Applications</option> </optgroup> <optgroup label="Advanced Active Record"> <option value="active_record_multiple_databases.html">Multiple Databases</option> <option value="active_record_composite_primary_keys.html">Composite Primary Keys</option> </optgroup> <optgroup label="Extending Rails"> <option value="rails_on_rack.html">Rails on Rack</option> <option value="generators.html">Creating and Customizing Rails Generators &amp; Templates</option> </optgroup> <optgroup label="Contributing"> <option value="contributing_to_ruby_on_rails.html">Contributing to Ruby on Rails</option> <option value="api_documentation_guidelines.html">API Documentation Guidelines</option> <option value="ruby_on_rails_guides_guidelines.html">Guides Guidelines</option> <option value="development_dependencies_install.html">Installing Rails Core Development Dependencies</option> </optgroup> <optgroup label="Policies"> <option value="maintenance_policy.html">Maintenance Policy</option> </optgroup> <optgroup label="Release Notes"> <option value="upgrading_ruby_on_rails.html">Upgrading Ruby on Rails</option> <option value="8_0_release_notes.html">Version 8.0 - November 2024</option> <option value="7_2_release_notes.html">Version 7.2 - August 2024</option> <option value="7_1_release_notes.html">Version 7.1 - October 2023</option> <option value="7_0_release_notes.html">Version 7.0 - December 2021</option> <option value="6_1_release_notes.html">Version 6.1 - December 2020</option> <option value="6_0_release_notes.html">Version 6.0 - August 2019</option> <option value="5_2_release_notes.html">Version 5.2 - April 2018</option> <option value="5_1_release_notes.html">Version 5.1 - April 2017</option> <option value="5_0_release_notes.html">Version 5.0 - June 2016</option> <option value="4_2_release_notes.html">Version 4.2 - December 2014</option> <option value="4_1_release_notes.html">Version 4.1 - April 2014</option> <option value="4_0_release_notes.html">Version 4.0 - June 2013</option> <option value="3_2_release_notes.html">Version 3.2 - January 2012</option> <option value="3_1_release_notes.html">Version 3.1 - August 2011</option> <option value="3_0_release_notes.html">Version 3.0 - August 2010</option> <option value="2_3_release_notes.html">Version 2.3 - March 2009</option> <option value="2_2_release_notes.html">Version 2.2 - November 2008</option> </optgroup> </select> </li> </ul> </nav> </div> </header> <hr class="hide" /> <main id="main"> <article> <header id="feature"> <div class="wrapper"> <h1>Contributing to Ruby on Rails</h1><p>This guide covers how <em>you</em> can become a part of the ongoing development of Ruby on Rails.</p><p>After reading this guide, you will know:</p> <ul> <li>How to use GitHub to report issues.</li> <li>How to clone main and run the test suite.</li> <li>How to help resolve existing issues.</li> <li>How to contribute to the Ruby on Rails documentation.</li> <li>How to contribute to the Ruby on Rails code.</li> </ul> <p>Ruby on Rails is not &quot;someone else&#39;s framework&quot;. Over the years, thousands of people have contributed to Ruby on Rails ranging from a single character to massive architectural changes or significant documentation - all to make Ruby on Rails better for everyone. Even if you don&#39;t feel up to writing code or documentation yet, there are various other ways that you can contribute, from reporting issues to testing patches.</p><p>As mentioned in <a href="https://github.com/rails/rails/blob/main/README.md">Rails&#39; README</a>, everyone interacting in Rails and its sub-projects&#39; codebases, issue trackers, chat rooms, discussion boards, and mailing lists is expected to follow the Rails <a href="https://rubyonrails.org/conduct">code of conduct</a>.</p> <nav id="column-side" aria-label="Chapter" class="guide-index" data-turbo="false"> <a id="chapter-nav-skip-link" href="#article-body" class="skip-link"> Skip to article body </a> <h2 class="chapter"> <picture aria-hidden="true"> <!-- Using the `source` HTML tag to set the dark theme image --> <source srcset="images/icon_book-close-bookmark-1-wht.svg" media="(prefers-color-scheme: dark)" /> <img src="images/icon_book-close-bookmark-1.svg" alt="Chapter Icon" /> </picture> Chapters </h2> <ol class="chapters"> <li><a href="#reporting-an-issue">Reporting an Issue</a> <ul> <li><a href="#creating-a-bug-report">Creating a Bug Report</a></li> <li><a href="#create-an-executable-test-case">Create an Executable Test Case</a></li> <li><a href="#special-treatment-for-security-issues">Special Treatment for Security Issues</a></li> <li><a href="#what-about-feature-requests-questionmark">What about Feature Requests?</a></li> </ul></li> <li><a href="#helping-to-resolve-existing-issues">Helping to Resolve Existing Issues</a> <ul> <li><a href="#verifying-bug-reports">Verifying Bug Reports</a></li> <li><a href="#testing-patches">Testing Patches</a></li> </ul></li> <li><a href="#contributing-to-the-rails-documentation">Contributing to the Rails Documentation</a></li> <li><a href="#translating-rails-guides">Translating Rails Guides</a></li> <li><a href="#contributing-to-the-rails-code">Contributing to the Rails Code</a> <ul> <li><a href="#setting-up-a-development-environment">Setting Up a Development Environment</a></li> <li><a href="#clone-the-rails-repository">Clone the Rails Repository</a></li> <li><a href="#bundle-install">Bundle install</a></li> <li><a href="#running-an-application-against-your-local-branch">Running an Application Against Your Local Branch</a></li> <li><a href="#write-your-code">Write Your Code</a></li> <li><a href="#benchmark-your-code">Benchmark Your Code</a></li> <li><a href="#running-tests">Running Tests</a></li> <li><a href="#warnings">Warnings</a></li> <li><a href="#updating-the-documentation">Updating the Documentation</a></li> <li><a href="#updating-the-changelog">Updating the CHANGELOG</a></li> <li><a href="#breaking-changes">Breaking Changes</a></li> <li><a href="#ignoring-files-created-by-your-editor-ide">Ignoring Files Created by Your Editor / IDE</a></li> <li><a href="#updating-the-gemfile-lock">Updating the Gemfile.lock</a></li> <li><a href="#commit-your-changes">Commit Your Changes</a></li> <li><a href="#update-your-branch">Update Your Branch</a></li> <li><a href="#fork">Fork</a></li> <li><a href="#open-a-pull-request">Open a Pull Request</a></li> <li><a href="#get-some-feedback">Get Some Feedback</a></li> <li><a href="#iterate-as-necessary">Iterate as Necessary</a></li> <li><a href="#older-versions-of-ruby-on-rails">Older Versions of Ruby on Rails</a></li> </ul></li> <li><a href="#rails-contributors">Rails Contributors</a></li> </ol> </nav> </div> </header> <div class="wrapper"> <div id="column-main"> <section id="article-body"> <h2 id="reporting-an-issue"><a class="anchorlink" href="#reporting-an-issue" data-turbo="false"><span>1.</span> Reporting an Issue</a></h2><p>Ruby on Rails uses <a href="https://github.com/rails/rails/issues">GitHub Issue Tracking</a> to track issues (primarily bugs and contributions of new code). If you've found a bug in Ruby on Rails, this is the place to start. You'll need to create a (free) GitHub account to submit an issue, comment on issues, or create pull requests.</p><div class="interstitial note"><p>Bugs in the most recent released version of Ruby on Rails will likely get the most attention. Additionally, the Rails core team is always interested in feedback from those who can take the time to test <em>edge Rails</em> (the code for the version of Rails that is currently under development). Later in this guide, you'll find out how to get edge Rails for testing. See our <a href="maintenance_policy.html">maintenance policy</a> for information on which versions are supported. Never report a security issue on the GitHub issues tracker.</p></div><h3 id="creating-a-bug-report"><a class="anchorlink" href="#creating-a-bug-report" data-turbo="false"><span>1.1.</span> Creating a Bug Report</a></h3><p>If you've found a problem in Ruby on Rails that is not a security risk, search the <a href="https://github.com/rails/rails/issues">Issues</a> on GitHub, in case it has already been reported. If you cannot find any open GitHub issues addressing the problem you found, your next step will be to <a href="https://github.com/rails/rails/issues/new">open a new issue</a>. (See the next section for reporting security issues.)</p><p>We've provided an issue template for you so that when creating an issue you include all the information needed to determine whether there is a bug in the framework. Each issue needs to include a title and clear description of the problem. Make sure to include as much relevant information as possible, including a code sample or failing test that demonstrates the expected behavior, as well as your system configuration. Your goal should be to make it easy for yourself - and others - to reproduce the bug and figure out a fix.</p><p>Once you open an issue, it may or may not see activity right away unless it is a "Code Red, Mission Critical, the World is Coming to an End" kind of bug. That doesn't mean we don't care about your bug, just that there are a lot of issues and pull requests to get through. Other people with the same problem can find your issue, and confirm the bug, and may collaborate with you on fixing it. If you know how to fix the bug, go ahead and open a pull request.</p><h3 id="create-an-executable-test-case"><a class="anchorlink" href="#create-an-executable-test-case" data-turbo="false"><span>1.2.</span> Create an Executable Test Case</a></h3><p>Having a way to reproduce your issue will help people confirm, investigate, and ultimately fix your issue. You can do this by providing an executable test case. To make this process easier, we have prepared several bug report templates for you to use as a starting point:</p> <ul> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record.rb">Template for Active Record (models, encryption, database) issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_record_migrations.rb">Template for testing Active Record (migration) issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_controller.rb">Template for Action Pack (controllers, routing) issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_view.rb">Template for Action View (views, helpers) issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_job.rb">Template for Active Job issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/active_storage.rb">Template for Active Storage issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailer.rb">Template for Action Mailer issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/action_mailbox.rb">Template for Action Mailbox issues</a></li> <li><a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/generic.rb">Generic template for other issues</a></li> </ul> <p>These templates include the boilerplate code to set up a test case. Copy the content of the appropriate template into a <code>.rb</code> file and make the necessary changes to demonstrate the issue. You can execute it by running <code>ruby the_file.rb</code> in your terminal. If all goes well, you should see your test case failing.</p><p>You can then share your executable test case as a <a href="https://gist.github.com">gist</a> or paste the content into the issue description.</p><h3 id="special-treatment-for-security-issues"><a class="anchorlink" href="#special-treatment-for-security-issues" data-turbo="false"><span>1.3.</span> Special Treatment for Security Issues</a></h3><div class="interstitial warning"><p>Please do not report security vulnerabilities with public GitHub issue reports. The <a href="https://rubyonrails.org/security">Rails security policy page</a> details the procedure to follow for security issues.</p></div><h3 id="what-about-feature-requests-questionmark"><a class="anchorlink" href="#what-about-feature-requests-questionmark" data-turbo="false"><span>1.4.</span> What about Feature Requests?</a></h3><p>Please don't put "feature request" items into GitHub Issues. If there's a new feature that you want to see added to Ruby on Rails, you'll need to write the code yourself - or convince someone else to partner with you to write the code. Later in this guide, you'll find detailed instructions for proposing a patch to Ruby on Rails. If you enter a wish list item in GitHub Issues with no code, you can expect it to be marked "invalid" as soon as it's reviewed.</p><p>Sometimes, the line between 'bug' and 'feature' is a hard one to draw. Generally, a feature is anything that adds new behavior, while a bug is anything that causes incorrect behavior. Sometimes, the Core team will have to make a judgment call. That said, the distinction generally determines which patch your change is released with; we love feature submissions! They just won't get backported to maintenance branches.</p><p>If you'd like feedback on an idea for a feature before doing the work to make a patch, please start a discussion on the <a href="https://discuss.rubyonrails.org/c/rubyonrails-core">rails-core discussion board</a>. You might get no response, which means that everyone is indifferent. You might find someone who's also interested in building that feature. You might get a "This won't be accepted". But it's the proper place to discuss new ideas. GitHub Issues are not a particularly good venue for the sometimes long and involved discussions new features require.</p><h2 id="helping-to-resolve-existing-issues"><a class="anchorlink" href="#helping-to-resolve-existing-issues" data-turbo="false"><span>2.</span> Helping to Resolve Existing Issues</a></h2><p>Beyond reporting issues, you can help the core team resolve existing ones by providing feedback about them. If you are new to Rails core development, providing feedback will help you get familiar with the codebase and the processes.</p><p>If you check the <a href="https://github.com/rails/rails/issues">issues list</a> in GitHub Issues, you'll find lots of issues already requiring attention. What can you do about these? Quite a bit, actually:</p><h3 id="verifying-bug-reports"><a class="anchorlink" href="#verifying-bug-reports" data-turbo="false"><span>2.1.</span> Verifying Bug Reports</a></h3><p>For starters, it helps just to verify bug reports. Can you reproduce the reported issue on your computer? If so, you can add a comment to the issue saying that you're seeing the same thing.</p><p>If an issue is very vague, can you help narrow it down to something more specific? Maybe you can provide additional information to reproduce the bug, or maybe you can eliminate unnecessary steps that aren't required to demonstrate the problem.</p><p>If you find a bug report without a test, it's very useful to contribute a failing test. This is also a great way to explore the source code: looking at the existing test files will teach you how to write more tests. New tests are best contributed in the form of a patch, as explained later on in the <a href="#contributing-to-the-rails-code">Contributing to the Rails Code</a> section.</p><p>Anything you can do to make bug reports more succinct or easier to reproduce helps folks trying to write code to fix those bugs - whether you end up writing the code yourself or not.</p><h3 id="testing-patches"><a class="anchorlink" href="#testing-patches" data-turbo="false"><span>2.2.</span> Testing Patches</a></h3><p>You can also help out by examining pull requests that have been submitted to Ruby on Rails via GitHub. In order to apply someone's changes, first create a dedicated branch:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout <span class="nt">-b</span> testing_branch </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout -b testing_branch ">Copy</button> </div> <p>Then, you can use their remote branch to update your codebase. For example, let's say the GitHub user JohnSmith has forked and pushed to a topic branch "orange" located at <a href="https://github.com/JohnSmith/rails">https://github.com/JohnSmith/rails</a>.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>remote add JohnSmith https://github.com/JohnSmith/rails.git <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>pull JohnSmith orange </code></pre> <button class="clipboard-button" data-clipboard-text="git remote add JohnSmith https://github.com/JohnSmith/rails.git git pull JohnSmith orange ">Copy</button> </div> <p>An alternative to adding their remote to your checkout is to use the <a href="https://cli.github.com/">GitHub CLI tool</a> to checkout their pull request.</p><p>After applying their branch, test it out! Here are some things to think about:</p> <ul> <li>Does the change actually work?</li> <li>Are you happy with the tests? Can you follow what they're testing? Are there any tests missing?</li> <li>Does it have the proper documentation coverage? Should documentation elsewhere be updated?</li> <li>Do you like the implementation? Can you think of a nicer or faster way to implement a part of their change?</li> </ul> <p>Once you're happy that the pull request contains a good change, comment on the GitHub issue indicating your findings. Your comment should indicate that you like the change and what you like about it. Something like:</p> <blockquote> <p>I like the way you've restructured that code in generate_finder_sql - much nicer. The tests look good too.</p></blockquote> <p>If your comment simply reads "+1", then odds are that other reviewers aren't going to take it too seriously. Show that you took the time to review the pull request.</p><h2 id="contributing-to-the-rails-documentation"><a class="anchorlink" href="#contributing-to-the-rails-documentation" data-turbo="false"><span>3.</span> Contributing to the Rails Documentation</a></h2><p>Ruby on Rails has two main sets of documentation: the guides, which help you learn about Ruby on Rails, and the API, which serves as a reference.</p><p>You can help improve the Rails guides or the API reference by making them more coherent, consistent, or readable, adding missing information, correcting factual errors, fixing typos, or bringing them up to date with the latest edge Rails.</p><p>To do so, make changes to Rails guides source files (located <a href="https://github.com/rails/rails/tree/main/guides/source">here</a> on GitHub) or RDoc comments in source code. Then open a pull request to apply your changes to the main branch.</p><p>Use <code>[ci skip]</code> in your pull request title to avoid running the CI build for documentation changes.</p><p>Once you open a PR, a preview of the documentation will be deployed for easy review and collaboration. At the bottom of the Pull Request page, you should see a list of status checks, look for the <code>buildkite/docs-preview</code> and click "details".</p><p><img src="images/docs_preview/status_checks.png" alt="GitHub rails/rails Pull Request status checks"></p><p>This will bring you to the Buildkite build page. If the job was successful, there will be an annotation with links to the generated API and Guides above the job list.</p><p><img src="images/docs_preview/annotation.png" alt="Buildkite rails/docs-preview annotation API &amp; Guides links"></p><p>When working with documentation, please take into account the <a href="api_documentation_guidelines.html">API Documentation Guidelines</a> and the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a>.</p><h2 id="translating-rails-guides"><a class="anchorlink" href="#translating-rails-guides" data-turbo="false"><span>4.</span> Translating Rails Guides</a></h2><p>We are happy to have people volunteer to translate the Rails guides. Just follow these steps:</p> <ul> <li>Fork <a href="https://github.com/rails/rails">https://github.com/rails/rails</a>.</li> <li>Add a source folder for your language, for example: <em>guides/source/it-IT</em> for Italian.</li> <li>Copy the contents of <em>guides/source</em> into your language directory and translate them.</li> <li>Do NOT translate the HTML files, as they are automatically generated.</li> </ul> <p>Note that translations are not submitted to the Rails repository; your work lives in your fork, as described above. This is because, in practice, documentation maintenance via patches is only sustainable in English.</p><p>To generate the guides in HTML format, you will need to install the guides dependencies, <code>cd</code> into the <em>guides</em> directory, and then run (e.g., for it-IT):</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nv">BUNDLE_ONLY</span><span class="o">=</span>default:doc <span class="nb">bundle install</span> <span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>guides/ <span class="gp">$</span><span class="w"> </span><span class="nv">BUNDLE_ONLY</span><span class="o">=</span>default:doc <span class="nb">bundle exec rake </span>guides:generate:html <span class="nv">GUIDES_LANGUAGE</span><span class="o">=</span>it-IT </code></pre> <button class="clipboard-button" data-clipboard-text="BUNDLE_ONLY=default:doc bundle install cd guides/ BUNDLE_ONLY=default:doc bundle exec rake guides:generate:html GUIDES_LANGUAGE=it-IT ">Copy</button> </div> <p>This will generate the guides in an <em>output</em> directory.</p><div class="interstitial note"><p>The Redcarpet Gem doesn't work with JRuby.</p></div><h2 id="contributing-to-the-rails-code"><a class="anchorlink" href="#contributing-to-the-rails-code" data-turbo="false"><span>5.</span> Contributing to the Rails Code</a></h2><h3 id="setting-up-a-development-environment"><a class="anchorlink" href="#setting-up-a-development-environment" data-turbo="false"><span>5.1.</span> Setting Up a Development Environment</a></h3><p>To move on from submitting bugs to helping resolve existing issues or contributing your own code to Ruby on Rails, you <em>must</em> be able to run its test suite. In this section of the guide, you'll learn how to set up the tests on your computer.</p><h4 id="using-github-codespaces"><a class="anchorlink" href="#using-github-codespaces" data-turbo="false"><span>5.1.1.</span> Using GitHub Codespaces</a></h4><p>If you're a member of an organization that has codespaces enabled, you can fork Rails into that organization and use codespaces on GitHub. The Codespace will be initialized with all required dependencies and allows you to run all tests.</p><h4 id="using-vs-code-remote-containers"><a class="anchorlink" href="#using-vs-code-remote-containers" data-turbo="false"><span>5.1.2.</span> Using VS Code Remote Containers</a></h4><p>If you have <a href="https://code.visualstudio.com">Visual Studio Code</a> and <a href="https://www.docker.com">Docker</a> installed, you can use the <a href="https://code.visualstudio.com/docs/remote/containers-tutorial">VS Code remote containers plugin</a>. The plugin will read the <a href="https://github.com/rails/rails/tree/main/.devcontainer"><code>.devcontainer</code></a> configuration in the repository and build the Docker container locally.</p><h4 id="using-dev-container-cli"><a class="anchorlink" href="#using-dev-container-cli" data-turbo="false"><span>5.1.3.</span> Using Dev Container CLI</a></h4><p>With <a href="https://github.com/npm/cli">npm</a> and <a href="https://www.docker.com">Docker</a> installed, you can run <a href="https://github.com/devcontainers/cli">Dev Container CLI</a> to utilize the <a href="https://github.com/rails/rails/tree/main/.devcontainer"><code>.devcontainer</code></a> configuration from the command line.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span>npm <span class="nb">install</span> <span class="nt">-g</span> @devcontainers/cli <span class="gp">$</span><span class="w"> </span><span class="nb">cd rails</span> <span class="gp">$</span><span class="w"> </span>devcontainer up <span class="nt">--workspace-folder</span> <span class="nb">.</span> <span class="gp">$</span><span class="w"> </span>devcontainer <span class="nb">exec</span> <span class="nt">--workspace-folder</span> <span class="nb">.</span> bash </code></pre> <button class="clipboard-button" data-clipboard-text="npm install -g @devcontainers/cli cd rails devcontainer up --workspace-folder . devcontainer exec --workspace-folder . bash ">Copy</button> </div> <h4 id="using-dev-container-with-podman"><a class="anchorlink" href="#using-dev-container-with-podman" data-turbo="false"><span>5.1.4.</span> Using Dev Container with Podman</a></h4><p>You can use the <a href="https://github.com/rails/rails/tree/main/.devcontainer"><code>.devcontainer</code></a> configuration with <a href="https://podman.io/">Podman</a>. This method does not require any other tools besides Podman.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span>podman machine init <span class="gp">$</span><span class="w"> </span>podman machine start <span class="gp">$</span><span class="w"> </span>tools/devcontainer up </code></pre> <button class="clipboard-button" data-clipboard-text="podman machine init podman machine start tools/devcontainer up ">Copy</button> </div> <p>Then in a separate terminal:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span>tools/devcontainer run-user-commands <span class="gp">$</span><span class="w"> </span>tools/devcontainer sh </code></pre> <button class="clipboard-button" data-clipboard-text="tools/devcontainer run-user-commands tools/devcontainer sh ">Copy</button> </div> <h4 id="using-rails-dev-box"><a class="anchorlink" href="#using-rails-dev-box" data-turbo="false"><span>5.1.5.</span> Using rails-dev-box</a></h4><p>It's also possible to use the <a href="https://github.com/rails/rails-dev-box">rails-dev-box</a> to get a development environment ready. However, the rails-dev-box uses Vagrant and Virtual Box which will not work on Macs with Apple silicon.</p><h4 id="local-development"><a class="anchorlink" href="#local-development" data-turbo="false"><span>5.1.6.</span> Local Development</a></h4><p>When you can't use GitHub Codespaces, see <a href="development_dependencies_install.html">this other guide</a> for how to set up local development. This is considered the hard way because installing dependencies may be OS specific.</p><h3 id="clone-the-rails-repository"><a class="anchorlink" href="#clone-the-rails-repository" data-turbo="false"><span>5.2.</span> Clone the Rails Repository</a></h3><p>To be able to contribute code, you need to clone the Rails repository:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>clone https://github.com/rails/rails.git </code></pre> <button class="clipboard-button" data-clipboard-text="git clone https://github.com/rails/rails.git ">Copy</button> </div> <p>and create a dedicated branch:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd rails</span> <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout <span class="nt">-b</span> my_new_branch </code></pre> <button class="clipboard-button" data-clipboard-text="cd rails git checkout -b my_new_branch ">Copy</button> </div> <p>It doesn't matter much what name you use because this branch will only exist on your local computer and your personal repository on GitHub. It won't be part of the Rails Git repository.</p><h3 id="bundle-install"><a class="anchorlink" href="#bundle-install" data-turbo="false"><span>5.3.</span> Bundle install</a></h3><p>Install the required gems.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">bundle install</span> </code></pre> <button class="clipboard-button" data-clipboard-text="bundle install ">Copy</button> </div> <h3 id="running-an-application-against-your-local-branch"><a class="anchorlink" href="#running-an-application-against-your-local-branch" data-turbo="false"><span>5.4.</span> Running an Application Against Your Local Branch</a></h3><p>In case you need a dummy Rails app to test changes, the <code>--dev</code> flag of <code>rails new</code> generates an application that uses your local branch:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd rails</span> <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rails </span>new ~/my-test-app <span class="nt">--dev</span> </code></pre> <button class="clipboard-button" data-clipboard-text="cd rails bundle exec rails new ~/my-test-app --dev ">Copy</button> </div> <p>The application generated in <code>~/my-test-app</code> runs against your local branch and, in particular, sees any modifications upon server reboot.</p><p>For JavaScript packages, you can use <a href="https://yarnpkg.com/cli/link"><code>yarn link</code></a> to source your local branch in a generated application:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd rails</span>/activestorage <span class="gp">$</span><span class="w"> </span><span class="nb">yarn link</span> <span class="gp">$</span><span class="w"> </span><span class="nb">cd</span> ~/my-test-app <span class="gp">$</span><span class="w"> </span><span class="nb">yarn link</span> <span class="s2">"@rails/activestorage"</span> </code></pre> <button class="clipboard-button" data-clipboard-text="cd rails/activestorage yarn link cd ~/my-test-app yarn link &quot;@rails/activestorage&quot; ">Copy</button> </div> <h3 id="write-your-code"><a class="anchorlink" href="#write-your-code" data-turbo="false"><span>5.5.</span> Write Your Code</a></h3><p>Now it's time to write some code! When making changes for Rails, here are some things to keep in mind:</p> <ul> <li>Follow Rails style and conventions.</li> <li>Use Rails idioms and helpers.</li> <li>Include tests that fail without your code, and pass with it.</li> <li>Update the (surrounding) documentation, examples elsewhere, and the guides: whatever is affected by your contribution.</li> <li>If the change adds, removes, or changes a feature, be sure to include a CHANGELOG entry. If your change is a bug fix, a CHANGELOG entry is not necessary.</li> </ul> <div class="interstitial info"><p>Changes that are cosmetic and do not add anything substantial to the stability, functionality, or testability of Rails will generally not be accepted (read more about <a href="https://github.com/rails/rails/pull/13771#issuecomment-32746700">our rationale behind this decision</a>).</p></div><h4 id="follow-the-coding-conventions"><a class="anchorlink" href="#follow-the-coding-conventions" data-turbo="false"><span>5.5.1.</span> Follow the Coding Conventions</a></h4><p>Rails follows a simple set of coding style conventions:</p> <ul> <li>Two spaces, no tabs (for indentation).</li> <li>No trailing whitespace. Blank lines should not have any spaces.</li> <li>Indent and no blank line after private/protected.</li> <li>Use Ruby &gt;= 1.9 syntax for hashes. Prefer <code>{ a: :b }</code> over <code>{ :a =&gt; :b }</code>.</li> <li>Prefer <code>&amp;&amp;</code>/<code>||</code> over <code>and</code>/<code>or</code>.</li> <li>Prefer <code>class &lt;&lt; self</code> over <code>self.method</code> for class methods.</li> <li>Use <code>my_method(my_arg)</code> not <code>my_method( my_arg )</code> or <code>my_method my_arg</code>.</li> <li>Use <code>a = b</code> and not <code>a=b</code>.</li> <li>Use <code>assert_not</code> methods instead of <code>refute</code>.</li> <li>Prefer <code>method { do_stuff }</code> instead of <code>method{do_stuff}</code> for single-line blocks.</li> <li>Follow the conventions in the source you see used already.</li> </ul> <p>The above are guidelines - please use your best judgment in using them.</p><p>Additionally, we have <a href="https://www.rubocop.org/">RuboCop</a> rules defined to codify some of our coding conventions. You can run RuboCop locally against the file that you have modified before submitting a pull request:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec </span>rubocop actionpack/lib/action_controller/metal/strong_parameters.rb <span class="go">Inspecting 1 file</span> <span class="c">.</span> <span class="go">1 file inspected, no offenses detected</span> </code></pre> <button class="clipboard-button" data-clipboard-text="bundle exec rubocop actionpack/lib/action_controller/metal/strong_parameters.rb ">Copy</button> </div> <h3 id="benchmark-your-code"><a class="anchorlink" href="#benchmark-your-code" data-turbo="false"><span>5.6.</span> Benchmark Your Code</a></h3><p>For changes that might have an impact on performance, please benchmark your code and measure the impact. Please share the benchmark script you used as well as the results. You should consider including this information in your commit message to allow future contributors to easily verify your findings and determine if they are still relevant. (For example, future optimizations in the Ruby VM might render certain optimizations unnecessary.)</p><p>When optimizing for a specific scenario that you care about, it is easy to regress performance for other common cases. Therefore, you should test your change against a list of representative scenarios, ideally extracted from real-world production applications.</p><p>You can use the <a href="https://github.com/rails/rails/blob/main/guides/bug_report_templates/benchmark.rb">benchmark template</a> as a starting point. It includes the boilerplate code to set up a benchmark using the <a href="https://github.com/evanphx/benchmark-ips">benchmark-ips</a> gem. The template is designed for testing relatively self-contained changes that can be inlined into the script.</p><h3 id="running-tests"><a class="anchorlink" href="#running-tests" data-turbo="false"><span>5.7.</span> Running Tests</a></h3><p>It is not customary in Rails to run the full test suite before pushing changes. The railties test suite, in particular, takes a long time, and will take an especially long time if the source code is mounted in <code>/vagrant</code> as happens in the recommended workflow with the <a href="https://github.com/rails/rails-dev-box">rails-dev-box</a>.</p><p>As a compromise, test what your code obviously affects, and if the change is not in railties, run the whole test suite of the affected component. If all tests are passing, that's enough to propose your contribution. We have <a href="https://buildkite.com/rails/rails">Buildkite</a> as a safety net for catching unexpected breakages elsewhere.</p><h4 id="entire-rails"><a class="anchorlink" href="#entire-rails" data-turbo="false"><span>5.7.1.</span> Entire Rails:</a></h4><p>To run all the tests, do:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd rails</span> <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span> </code></pre> <button class="clipboard-button" data-clipboard-text="cd rails bundle exec rake test ">Copy</button> </div> <h4 id="for-a-particular-component"><a class="anchorlink" href="#for-a-particular-component" data-turbo="false"><span>5.7.2.</span> For a Particular Component</a></h4><p>You can run tests only for a particular component (e.g., Action Pack). For example, to run Action Mailer tests:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionmailer <span class="gp">$</span><span class="w"> </span>bin/test </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionmailer bin/test ">Copy</button> </div> <h4 id="for-a-specific-directory"><a class="anchorlink" href="#for-a-specific-directory" data-turbo="false"><span>5.7.3.</span> For a Specific Directory</a></h4><p>You can run tests only for a specific directory of a particular component (e.g., models in Active Storage). For example, to run tests in <code>/activestorage/test/models</code>:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>activestorage <span class="gp">$</span><span class="w"> </span>bin/test models </code></pre> <button class="clipboard-button" data-clipboard-text="cd activestorage bin/test models ">Copy</button> </div> <h4 id="for-a-specific-file"><a class="anchorlink" href="#for-a-specific-file" data-turbo="false"><span>5.7.4.</span> For a Specific File</a></h4><p>You can run the tests for a particular file:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionview <span class="gp">$</span><span class="w"> </span>bin/test <span class="nb">test</span>/template/form_helper_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionview bin/test test/template/form_helper_test.rb ">Copy</button> </div> <h4 id="running-a-single-test"><a class="anchorlink" href="#running-a-single-test" data-turbo="false"><span>5.7.5.</span> Running a Single Test</a></h4><p>You can run a single test by name using the <code>-n</code> option:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionmailer <span class="gp">$</span><span class="w"> </span>bin/test <span class="nb">test</span>/mail_layout_test.rb <span class="nt">-n</span> test_explicit_class_layout </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionmailer bin/test test/mail_layout_test.rb -n test_explicit_class_layout ">Copy</button> </div> <h4 id="for-a-specific-line"><a class="anchorlink" href="#for-a-specific-line" data-turbo="false"><span>5.7.6.</span> For a Specific Line</a></h4><p>Figuring out the name is not always easy, but if you know the line number your test starts at, this option is for you:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>railties <span class="gp">$</span><span class="w"> </span>bin/test <span class="nb">test</span>/application/asset_debugging_test.rb:69 </code></pre> <button class="clipboard-button" data-clipboard-text="cd railties bin/test test/application/asset_debugging_test.rb:69 ">Copy</button> </div> <h4 id="for-a-specific-line-range"><a class="anchorlink" href="#for-a-specific-line-range" data-turbo="false"><span>5.7.7.</span> For a Specific Line Range</a></h4><p>Similar tests are often defined in nearby locations. You can run tests in a specific line range.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>railties <span class="gp">$</span><span class="w"> </span>bin/test <span class="nb">test</span>/application/asset_debugging_test.rb:69-100 </code></pre> <button class="clipboard-button" data-clipboard-text="cd railties bin/test test/application/asset_debugging_test.rb:69-100 ">Copy</button> </div> <h4 id="running-tests-with-a-specific-seed"><a class="anchorlink" href="#running-tests-with-a-specific-seed" data-turbo="false"><span>5.7.8.</span> Running Tests with a Specific Seed</a></h4><p>Test execution is randomized with a randomization seed. If you are experiencing random test failures, you can more accurately reproduce a failing test scenario by specifically setting the randomization seed.</p><p>Running all tests for a component:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionmailer <span class="gp">$</span><span class="w"> </span><span class="nv">SEED</span><span class="o">=</span>15002 bin/test </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionmailer SEED=15002 bin/test ">Copy</button> </div> <p>Running a single test file:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionmailer <span class="gp">$</span><span class="w"> </span><span class="nv">SEED</span><span class="o">=</span>15002 bin/test <span class="nb">test</span>/mail_layout_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionmailer SEED=15002 bin/test test/mail_layout_test.rb ">Copy</button> </div> <h4 id="running-tests-in-serial"><a class="anchorlink" href="#running-tests-in-serial" data-turbo="false"><span>5.7.9.</span> Running Tests in Serial</a></h4><p>Action Pack and Action View unit tests run in parallel by default. If you are experiencing random test failures, you can set the randomization seed and let these unit tests run in serial by setting <code>PARALLEL_WORKERS=1</code></p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>actionview <span class="gp">$</span><span class="w"> </span><span class="nv">PARALLEL_WORKERS</span><span class="o">=</span>1 <span class="nv">SEED</span><span class="o">=</span>53708 bin/test <span class="nb">test</span>/template/test_case_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="cd actionview PARALLEL_WORKERS=1 SEED=53708 bin/test test/template/test_case_test.rb ">Copy</button> </div> <h4 id="testing-active-record"><a class="anchorlink" href="#testing-active-record" data-turbo="false"><span>5.7.10.</span> Testing Active Record</a></h4><p>First, create the databases you'll need. You can find a list of the required table names, usernames, and passwords in <code>activerecord/test/config.example.yml</code>.</p><p>For MySQL and PostgreSQL, it is sufficient to run:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>activerecord <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake </span>db:mysql:build </code></pre> <button class="clipboard-button" data-clipboard-text="cd activerecord bundle exec rake db:mysql:build ">Copy</button> </div> <p>Or:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>activerecord <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake </span>db:postgresql:build </code></pre> <button class="clipboard-button" data-clipboard-text="cd activerecord bundle exec rake db:postgresql:build ">Copy</button> </div> <p>This is not necessary for SQLite3.</p><p>This is how you run the Active Record test suite only for SQLite3:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">cd </span>activerecord <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span>:sqlite3 </code></pre> <button class="clipboard-button" data-clipboard-text="cd activerecord bundle exec rake test:sqlite3 ">Copy</button> </div> <p>You can now run the tests as you did for <code>sqlite3</code>. The tasks are respectively:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span>:mysql2 <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span>:trilogy <span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span>:postgresql </code></pre> <button class="clipboard-button" data-clipboard-text="bundle exec rake test:mysql2 bundle exec rake test:trilogy bundle exec rake test:postgresql ">Copy</button> </div> <p>Finally,</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake test</span> </code></pre> <button class="clipboard-button" data-clipboard-text="bundle exec rake test ">Copy</button> </div> <p>will now run the three of them in turn.</p><p>You can also run any single test separately:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nv">ARCONN</span><span class="o">=</span>mysql2 <span class="nb">bundle exec ruby</span> <span class="nt">-Itest</span> <span class="nb">test</span>/cases/associations/has_many_associations_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="ARCONN=mysql2 bundle exec ruby -Itest test/cases/associations/has_many_associations_test.rb ">Copy</button> </div> <p>To run a single test against all adapters, use:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">bundle exec rake </span><span class="nv">TEST</span><span class="o">=</span><span class="nb">test</span>/cases/associations/has_many_associations_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="bundle exec rake TEST=test/cases/associations/has_many_associations_test.rb ">Copy</button> </div> <p>You can invoke <code>test_jdbcmysql</code>, <code>test_jdbcsqlite3</code> or <code>test_jdbcpostgresql</code> also. See the file <code>activerecord/RUNNING_UNIT_TESTS.rdoc</code> for information on running more targeted database tests.</p><h4 id="using-debuggers-with-test"><a class="anchorlink" href="#using-debuggers-with-test" data-turbo="false"><span>5.7.11.</span> Using Debuggers with Test</a></h4><p>To use an external debugger (pry, byebug, etc), install the debugger and use it as normal. If debugger issues occur, run tests in serial by setting <code>PARALLEL_WORKERS=1</code> or run a single test with <code>-n test_long_test_name</code>.</p><p>If running tests against generators, you will need to set <code>RAILS_LOG_TO_STDOUT=true</code> in order for debugging tools to work.</p><div class="interstitial code"> <pre><code class="highlight sh"><span class="nv">RAILS_LOG_TO_STDOUT</span><span class="o">=</span><span class="nb">true</span> ./bin/test <span class="nb">test</span>/generators/actions_test.rb </code></pre> <button class="clipboard-button" data-clipboard-text="RAILS_LOG_TO_STDOUT=true ./bin/test test/generators/actions_test.rb ">Copy</button> </div> <h3 id="warnings"><a class="anchorlink" href="#warnings" data-turbo="false"><span>5.8.</span> Warnings</a></h3><p>The test suite runs with warnings enabled. Ideally, Ruby on Rails should issue no warnings, but there may be a few, as well as some from third-party libraries. Please ignore (or fix!) them, if any, and submit patches that do not issue new warnings.</p><p>Rails CI will raise if warnings are introduced. To implement the same behavior locally, set <code>RAILS_STRICT_WARNINGS=1</code> when running the test suite.</p><h3 id="updating-the-documentation"><a class="anchorlink" href="#updating-the-documentation" data-turbo="false"><span>5.9.</span> Updating the Documentation</a></h3><p>The Ruby on Rails <a href="https://guides.rubyonrails.org/">guides</a> provide a high-level overview of Rails' features, while the <a href="https://edgeapi.rubyonrails.org/">API documentation</a> delves into specifics.</p><p>If your PR adds a new feature or changes how an existing feature behaves, check the relevant documentation and update it or add to it as necessary.</p><p>For example, if you modify Active Storage's image analyzer to add a new metadata field, you should update the <a href="active_storage_overview.html#analyzing-files">Analyzing Files</a> section of the Active Storage guide to reflect that.</p><h3 id="updating-the-changelog"><a class="anchorlink" href="#updating-the-changelog" data-turbo="false"><span>5.10.</span> Updating the CHANGELOG</a></h3><p>The CHANGELOG is an important part of every release. It keeps the list of changes for every Rails version.</p><p>You should add an entry <strong>to the top</strong> of the CHANGELOG of the framework you modified if you're adding or removing a feature, or adding deprecation notices. Refactorings, minor bug fixes, and documentation changes generally should not go to the CHANGELOG.</p><p>A CHANGELOG entry should summarize what was changed and should end with the author's name. You can use multiple lines if you need more space, and you can attach code examples indented with 4 spaces. If a change is related to a specific issue, you should attach the issue's number. Here is an example CHANGELOG entry:</p><div class="interstitial code"> <pre><code class="highlight markdown"><span class="p">*</span> Summary of a change that briefly describes what was changed. You can use multiple lines and wrap them at around 80 characters. Code examples are ok, too, if needed: <span class="sb"> class Foo</span> <span class="sb"> def bar</span> <span class="sb"> puts 'baz'</span> <span class="sb"> end</span> <span class="sb"> end</span> <span class="sb"> You can continue after the code example, and you can attach the issue number.</span> <span class="sb"> Fixes #1234.</span> <span class="sb"> *Your Name*</span> </code></pre> <button class="clipboard-button" data-clipboard-text="* Summary of a change that briefly describes what was changed. You can use multiple lines and wrap them at around 80 characters. Code examples are ok, too, if needed: class Foo def bar puts 'baz' end end You can continue after the code example, and you can attach the issue number. Fixes #1234. *Your Name* ">Copy</button> </div> <h3 id="breaking-changes"><a class="anchorlink" href="#breaking-changes" data-turbo="false"><span>5.11.</span> Breaking Changes</a></h3><p>Anytime a change could break existing applications, it's considered a breaking change. To ease upgrading Rails applications, breaking changes require a deprecation cycle.</p><h4 id="removing-behavior"><a class="anchorlink" href="#removing-behavior" data-turbo="false"><span>5.11.1.</span> Removing Behavior</a></h4><p>If your breaking change removes existing behavior, you'll first need to add a deprecation warning while keeping the existing behavior.</p><p>As an example, let's say you want to remove a public method on <code>ActiveRecord::Base</code>. If the main branch points to the unreleased 7.0 version, Rails 7.0 will need to show a deprecation warning. This makes sure anyone upgrading to any Rails 7.0 version will see the deprecation warning. In Rails 7.1 the method can be deleted.</p><p>You could add the following deprecation warning:</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="k">def</span> <span class="nf">deprecated_method</span> <span class="no">ActiveRecord</span><span class="p">.</span><span class="nf">deprecator</span><span class="p">.</span><span class="nf">warn</span><span class="p">(</span><span class="o">&lt;&lt;-</span><span class="no">MSG</span><span class="p">.</span><span class="nf">squish</span><span class="p">)</span> <span class="sh"> `ActiveRecord::Base.deprecated_method` is deprecated and will be removed in Rails 7.1.</span> <span class="no"> MSG</span> <span class="c1"># Existing behavior</span> <span class="k">end</span> </code></pre> <button class="clipboard-button" data-clipboard-text="def deprecated_method ActiveRecord.deprecator.warn(<<-MSG.squish) `ActiveRecord::Base.deprecated_method` is deprecated and will be removed in Rails 7.1. MSG # Existing behavior end ">Copy</button> </div> <h4 id="changing-behavior"><a class="anchorlink" href="#changing-behavior" data-turbo="false"><span>5.11.2.</span> Changing Behavior</a></h4><p>If your breaking change changes existing behavior, you'll need to add a framework default. Framework defaults ease Rails upgrades by allowing apps to switch to the new defaults one by one.</p><p>To implement a new framework default, first create a configuration by adding an accessor on the target framework. Set the default value to the existing behavior to make sure nothing breaks during an upgrade.</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="k">module</span> <span class="nn">ActiveJob</span> <span class="n">mattr_accessor</span> <span class="ss">:existing_behavior</span><span class="p">,</span> <span class="ss">default: </span><span class="kp">true</span> <span class="k">end</span> </code></pre> <button class="clipboard-button" data-clipboard-text="module ActiveJob mattr_accessor :existing_behavior, default: true end ">Copy</button> </div> <p>The new configuration allows you to conditionally implement the new behavior:</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="k">def</span> <span class="nf">changed_method</span> <span class="k">if</span> <span class="no">ActiveJob</span><span class="p">.</span><span class="nf">existing_behavior</span> <span class="c1"># Existing behavior</span> <span class="k">else</span> <span class="c1"># New behavior</span> <span class="k">end</span> <span class="k">end</span> </code></pre> <button class="clipboard-button" data-clipboard-text="def changed_method if ActiveJob.existing_behavior # Existing behavior else # New behavior end end ">Copy</button> </div> <p>To set the new framework default, set the new value in <code>Rails::Application::Configuration#load_defaults</code>:</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="k">def</span> <span class="nf">load_defaults</span><span class="p">(</span><span class="n">target_version</span><span class="p">)</span> <span class="k">case</span> <span class="n">target_version</span><span class="p">.</span><span class="nf">to_s</span> <span class="k">when</span> <span class="s2">"7.1"</span> <span class="c1"># ...</span> <span class="k">if</span> <span class="nb">respond_to?</span><span class="p">(</span><span class="ss">:active_job</span><span class="p">)</span> <span class="n">active_job</span><span class="p">.</span><span class="nf">existing_behavior</span> <span class="o">=</span> <span class="kp">false</span> <span class="k">end</span> <span class="c1"># ...</span> <span class="k">end</span> <span class="k">end</span> </code></pre> <button class="clipboard-button" data-clipboard-text="def load_defaults(target_version) case target_version.to_s when &quot;7.1&quot; # ... if respond_to?(:active_job) active_job.existing_behavior = false end # ... end end ">Copy</button> </div> <p>To ease the upgrade it's required to add the new default to the <code>new_framework_defaults</code> template. Add a commented out section, setting the new value:</p><div class="interstitial code"> <pre><code class="highlight ruby"><span class="c1"># new_framework_defaults_8_1.rb.tt</span> <span class="c1"># Rails.application.config.active_job.existing_behavior = false</span> </code></pre> <button class="clipboard-button" data-clipboard-text="# new_framework_defaults_8_1.rb.tt # Rails.application.config.active_job.existing_behavior = false ">Copy</button> </div> <p>As a last step, add the new configuration to configuration guide in <code>configuration.md</code>:</p><div class="interstitial code"> <pre><code class="highlight markdown"><span class="gu">#### `config.active_job.existing_behavior</span> | Starting with version | The default value is | | --------------------- | -------------------- | | (original) | <span class="sb">`true`</span> | | 7.1 | <span class="sb">`false`</span> | </code></pre> <button class="clipboard-button" data-clipboard-text="#### `config.active_job.existing_behavior | Starting with version | The default value is | | --------------------- | -------------------- | | (original) | `true` | | 7.1 | `false` | ">Copy</button> </div> <h3 id="ignoring-files-created-by-your-editor-ide"><a class="anchorlink" href="#ignoring-files-created-by-your-editor-ide" data-turbo="false"><span>5.12.</span> Ignoring Files Created by Your Editor / IDE</a></h3><p>Some editors and IDEs will create hidden files or folders inside the <code>rails</code> folder. Instead of manually excluding those from each commit or adding them to Rails' <code>.gitignore</code>, you should add them to your own <a href="https://docs.github.com/en/get-started/getting-started-with-git/ignoring-files#configuring-ignored-files-for-all-repositories-on-your-computer">global gitignore file</a>.</p><h3 id="updating-the-gemfile-lock"><a class="anchorlink" href="#updating-the-gemfile-lock" data-turbo="false"><span>5.13.</span> Updating the Gemfile.lock</a></h3><p>Some changes require dependency upgrades. In these cases, make sure you run <code>bundle update</code> to get the correct version of the dependency and commit the <code>Gemfile.lock</code> file within your changes.</p><h3 id="commit-your-changes"><a class="anchorlink" href="#commit-your-changes" data-turbo="false"><span>5.14.</span> Commit Your Changes</a></h3><p>When you're happy with the code on your computer, you need to commit the changes to Git:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>commit <span class="nt">-a</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git commit -a ">Copy</button> </div> <p>This should fire up your editor to write a commit message. When you have finished, save, and close to continue.</p><p>A well-formatted and descriptive commit message is very helpful to others for understanding why the change was made, so please take the time to write it.</p><p>A good commit message looks like this:</p><div class="interstitial code"> <pre><code class="highlight markdown">Short summary (ideally 50 characters or less) More detailed description, if necessary. Each line should wrap at 72 characters. Try to be as descriptive as you can. Even if you think that the commit content is obvious, it may not be obvious to others. Add any description that is already present in the relevant issues; it should not be necessary to visit a webpage to check the history. The description section can have multiple paragraphs. Code examples can be embedded by indenting them with 4 spaces: <span class="sb"> class ArticlesController</span> <span class="sb"> def index</span> <span class="sb"> render json: Article.limit(10)</span> <span class="sb"> end</span> <span class="sb"> end</span> You can also add bullet points: <span class="p">-</span> make a bullet point by starting a line with either a dash (-) or an asterisk (<span class="err">*</span>) <span class="p">-</span> wrap lines at 72 characters, and indent any additional lines with 2 spaces for readability </code></pre> <button class="clipboard-button" data-clipboard-text="Short summary (ideally 50 characters or less) More detailed description, if necessary. Each line should wrap at 72 characters. Try to be as descriptive as you can. Even if you think that the commit content is obvious, it may not be obvious to others. Add any description that is already present in the relevant issues; it should not be necessary to visit a webpage to check the history. The description section can have multiple paragraphs. Code examples can be embedded by indenting them with 4 spaces: class ArticlesController def index render json: Article.limit(10) end end You can also add bullet points: - make a bullet point by starting a line with either a dash (-) or an asterisk (*) - wrap lines at 72 characters, and indent any additional lines with 2 spaces for readability ">Copy</button> </div> <div class="interstitial info"><p>Please squash your commits into a single commit when appropriate. This simplifies future cherry picks and keeps the git log clean.</p></div><h3 id="update-your-branch"><a class="anchorlink" href="#update-your-branch" data-turbo="false"><span>5.15.</span> Update Your Branch</a></h3><p>It's pretty likely that other changes to main have happened while you were working. To get new changes in main:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout main <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>pull <span class="nt">--rebase</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout main git pull --rebase ">Copy</button> </div> <p>Now reapply your patch on top of the latest changes:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout my_new_branch <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>rebase main </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout my_new_branch git rebase main ">Copy</button> </div> <p>No conflicts? Tests still pass? Change still seems reasonable to you? Then push the rebased changes to GitHub:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>push <span class="nt">--force-with-lease</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git push --force-with-lease ">Copy</button> </div> <p>We disallow force pushing on the rails/rails repository base, but you are able to force push to your fork. When rebasing, this is a requirement since the history has changed.</p><h3 id="fork"><a class="anchorlink" href="#fork" data-turbo="false"><span>5.16.</span> Fork</a></h3><p>Navigate to the Rails <a href="https://github.com/rails/rails">GitHub repository</a> and press "Fork" in the upper right-hand corner.</p><p>Add the new remote to your local repository on your local machine:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>remote add fork https://github.com/&lt;your username&gt;/rails.git </code></pre> <button class="clipboard-button" data-clipboard-text="git remote add fork https://github.com/<your username>/rails.git ">Copy</button> </div> <p>You may have cloned your local repository from rails/rails, or you may have cloned from your forked repository. The following git commands assume that you have made a "rails" remote that points to rails/rails.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>remote add <span class="nb">rails </span>https://github.com/rails/rails.git </code></pre> <button class="clipboard-button" data-clipboard-text="git remote add rails https://github.com/rails/rails.git ">Copy</button> </div> <p>Download new commits and branches from the official repository:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>fetch <span class="nb">rails</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git fetch rails ">Copy</button> </div> <p>Merge the new content:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout main <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>rebase <span class="nb">rails</span>/main <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout my_new_branch <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>rebase <span class="nb">rails</span>/main </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout main git rebase rails/main git checkout my_new_branch git rebase rails/main ">Copy</button> </div> <p>Update your fork:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>push fork main <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>push fork my_new_branch </code></pre> <button class="clipboard-button" data-clipboard-text="git push fork main git push fork my_new_branch ">Copy</button> </div> <h3 id="open-a-pull-request"><a class="anchorlink" href="#open-a-pull-request" data-turbo="false"><span>5.17.</span> Open a Pull Request</a></h3><p>Navigate to the Rails repository you just pushed to (e.g., <a href="https://github.com/your-user-name/rails">https://github.com/your-user-name/rails</a>) and click on "Pull Requests" in the top bar (just above the code). On the next page, click "New pull request" in the upper right-hand corner.</p><p>The pull request should target the base repository <code>rails/rails</code> and the branch <code>main</code>. The head repository will be your work (<code>your-user-name/rails</code>), and the branch will be whatever name you gave your branch. Click "create pull request" when you're ready.</p><p>Ensure the changesets you introduced are included. Fill in some details about your potential patch, using the pull request template provided. When finished, click "Create pull request".</p><h3 id="get-some-feedback"><a class="anchorlink" href="#get-some-feedback" data-turbo="false"><span>5.18.</span> Get Some Feedback</a></h3><p>Most pull requests will go through a few iterations before they get merged. Different contributors will sometimes have different opinions, and often patches will need to be revised before they can get merged.</p><p>Some contributors to Rails have email notifications from GitHub turned on, but others do not. Furthermore, (almost) everyone who works on Rails is a volunteer, and so it may take a few days for you to get your first feedback on a pull request. Don't despair! Sometimes it's quick; sometimes it's slow. Such is the open source life.</p><p>If it's been over a week, and you haven't heard anything, you might want to try and nudge things along. You can use the <em>contributions</em> channel in the <a href="https://discord.gg/d8N68BCw49">Ruby on Rails Discord server</a>, or the <a href="https://discuss.rubyonrails.org/c/rubyonrails-core">rubyonrails-core discussion board</a> for this. You can also leave another comment on the pull request. It's best to avoid pinging individual maintainers directly as we have limited bandwidth and may not be able to look at your PR.</p><p>While you're waiting for feedback on your pull request, open up a few other pull requests and give someone else some! They'll appreciate it in the same way that you appreciate feedback on your patches.</p><p>Note that only the Core and Committers teams are permitted to merge code changes. If someone gives feedback and "approves" your changes, they may not have the ability or final say to merge your change.</p><h3 id="iterate-as-necessary"><a class="anchorlink" href="#iterate-as-necessary" data-turbo="false"><span>5.19.</span> Iterate as Necessary</a></h3><p>It's entirely possible that the feedback you get will suggest changes. Don't get discouraged: the whole point of contributing to an active open source project is to tap into the community's knowledge. If people encourage you to tweak your code, then it's worth making the tweaks and resubmitting. If the feedback is that your code won't be merged, you might still think about releasing it as a gem.</p><h4 id="squashing-commits"><a class="anchorlink" href="#squashing-commits" data-turbo="false"><span>5.19.1.</span> Squashing Commits</a></h4><p>One of the things that we may ask you to do is to "squash your commits", which will combine all of your commits into a single commit. We prefer pull requests that are a single commit. This makes it easier to backport changes to stable branches, squashing makes it easier to revert bad commits, and the git history can be a bit easier to follow. Rails is a large project, and a bunch of extraneous commits can add a lot of noise.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>fetch <span class="nb">rails</span> <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout my_new_branch <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>rebase <span class="nt">-i</span> <span class="nb">rails</span>/main <span class="gp">&lt; Choose 'squash' for all of your commits except the first one. &gt;</span> <span class="gp">&lt; Edit the commit message to make sense, and describe all your changes. &gt;</span> <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>push fork my_new_branch <span class="nt">--force-with-lease</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git fetch rails git checkout my_new_branch git rebase -i rails/main git push fork my_new_branch --force-with-lease ">Copy</button> </div> <p>You should be able to refresh the pull request on GitHub and see that it has been updated.</p><h4 id="updating-a-pull-request"><a class="anchorlink" href="#updating-a-pull-request" data-turbo="false"><span>5.19.2.</span> Updating a Pull Request</a></h4><p>Sometimes you will be asked to make some changes to the code you have already committed. This can include amending existing commits. In this case Git will not allow you to push the changes as the pushed branch and local branch do not match. Instead of opening a new pull request, you can force push to your branch on GitHub as described earlier in squashing commits section:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>commit <span class="nt">--amend</span> <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>push fork my_new_branch <span class="nt">--force-with-lease</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git commit --amend git push fork my_new_branch --force-with-lease ">Copy</button> </div> <p>This will update the branch and pull request on GitHub with your new code. By force pushing with <code>--force-with-lease</code>, git will more safely update the remote than with a typical <code>-f</code>, which can delete work from the remote that you don't already have.</p><h3 id="older-versions-of-ruby-on-rails"><a class="anchorlink" href="#older-versions-of-ruby-on-rails" data-turbo="false"><span>5.20.</span> Older Versions of Ruby on Rails</a></h3><p>If you want to add a fix to versions of Ruby on Rails older than the next release, you'll need to set up and switch to your own local tracking branch. Here is an example to switch to the 7-0-stable branch:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>branch <span class="nt">--track</span> 7-0-stable <span class="nb">rails</span>/7-0-stable <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout 7-0-stable </code></pre> <button class="clipboard-button" data-clipboard-text="git branch --track 7-0-stable rails/7-0-stable git checkout 7-0-stable ">Copy</button> </div> <div class="interstitial note"><p>Before working on older versions, please check the <a href="maintenance_policy.html">maintenance policy</a>. Changes will not be accepted to versions that have reached end of life.</p></div><h4 id="backporting"><a class="anchorlink" href="#backporting" data-turbo="false"><span>5.20.1.</span> Backporting</a></h4><p>Changes that are merged into main are intended for the next major release of Rails. Sometimes, it might be beneficial to propagate your changes back to stable branches for inclusion in maintenance releases. Generally, security fixes and bug fixes are good candidates for a backport, while new features and patches that change expected behavior will not be accepted. When in doubt, it is best to consult a Rails team member before backporting your changes to avoid wasted effort.</p><p>First, make sure your main branch is up to date.</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout main <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>pull <span class="nt">--rebase</span> </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout main git pull --rebase ">Copy</button> </div> <p>Check out the branch you're backporting to, for example, <code>7-0-stable</code> and make sure it's up to date:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout 7-0-stable <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>reset <span class="nt">--hard</span> origin/7-0-stable <span class="gp">$</span><span class="w"> </span><span class="nb">git </span>checkout <span class="nt">-b</span> my-backport-branch </code></pre> <button class="clipboard-button" data-clipboard-text="git checkout 7-0-stable git reset --hard origin/7-0-stable git checkout -b my-backport-branch ">Copy</button> </div> <p>If you're backporting a merged pull request, find the commit for the merge and cherry-pick it:</p><div class="interstitial code"> <pre><code class="highlight console"><span class="gp">$</span><span class="w"> </span><span class="nb">git </span>cherry-pick <span class="nt">-m1</span> MERGE_SHA </code></pre> <button class="clipboard-button" data-clipboard-text="git cherry-pick -m1 MERGE_SHA ">Copy</button> </div> <p>Fix any conflicts that occurred in the cherry-pick, push your changes, then open a PR pointing at the stable branch you're backporting to. If you have a more complex set of changes, the <a href="https://git-scm.com/docs/git-cherry-pick">cherry-pick</a> documentation can help.</p><h2 id="rails-contributors"><a class="anchorlink" href="#rails-contributors" data-turbo="false"><span>6.</span> Rails Contributors</a></h2><p>All contributions get credit in <a href="https://contributors.rubyonrails.org">Rails Contributors</a>.</p> </section> <hr> <footer aria-labelledby="heading-feedback" role="region"> <h2 id="heading-feedback">Feedback</h2> <p> You're encouraged to help improve the quality of this guide. </p> <p> Please contribute if you see any typos or factual errors. To get started, you can read our <a href="https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#contributing-to-the-rails-documentation">documentation contributions</a> section. </p> <p> You may also find incomplete content or stuff that is not up to date. Please do add any missing documentation for main. Make sure to check <a href="https://edgeguides.rubyonrails.org">Edge Guides</a> first to verify if the issues are already fixed or not on the main branch. Check the <a href="ruby_on_rails_guides_guidelines.html">Ruby on Rails Guides Guidelines</a> for style and conventions. </p> <p> If for whatever reason you spot something to fix but cannot patch it yourself, please <a href="https://github.com/rails/rails/issues">open an issue</a>. </p> <p>And last but not least, any kind of discussion regarding Ruby on Rails documentation is very welcome on the <a href="https://discuss.rubyonrails.org/c/rubyonrails-docs">official Ruby on Rails Forum</a>. </p> </footer> </div> </article> </main> <hr class="hide" /> <footer id="complementary"> <div class="wrapper"> <p>This work is licensed under a <a href="https://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International</a> License</p> <p>"Rails", "Ruby on Rails", and the Rails logo are trademarks of David Heinemeier Hansson. All rights reserved.</p> </div> </footer> <a href="#main-skip-link" class="back-to-top" data-turbo="false"><span class="visibly-hidden">Back to top</span></a> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10