1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
Ruby on Rails
Find a file
eileencodes 49b6b211a9 Move schema cache from connection to pool
This PR proposes moving the schema cache from the connection to the pool
so the connection can ask the pool for the cache. In a future PR our
goal is to be able to read the yaml file from the pool so we can get
rid of the `active_record.check_schema_cache_dump` initializer. This
will fix the issues surrounding dumping the schema cache and mulitple
databases.

Why do we want to get rid of the initializer you ask?

Well I was looking at #34449 and trying to make it work for our usecase
and it revealed A LOT of problems. There are a few issues that I will
fix in remaining PRs with SchemaMigration, but there's a big glaring
issue with this initializer.

When you have an application with multiple databases we'll need to loop
through all the configurations and set the schema cache on those
connections. The problem is on initialization we only have one
connection - the one for Ar::Base. This is fine in a single db
application but not fine in multi-db. If we follow the pattern in #34449
and establish a connection to those other dbs we will end up setting the
cache on the _connection object_ rather than on all connections that
connect for that config.

So even though we looped through the configs and assigned the cache the
cache will not be set (or will be set wrong) once the app is booted
because the connection objects after boot are _different_ than the
connection objects we assigned the cache to.

After trying many different ways to set the schema cache `@tenderlove`
and I came to the conclusion that the initializer is problematic, as is
setting the schema cache twice.

This is part 1 to move the cache to the pool so the cache can read from
the schema cache yaml file instead of setting it when initializing the
app.

To do this we have created a `NullPool` that initializes an empty cache. I
put the `get_schema_cache` and `set_schema_cache` in an `AbstractPool`
so we can share code between `ConnectionPool` and `NullPool` instead of
duplicating code.

Now we only need to set the schema_cache on the pool rather than the
connection. In `discard!` we need to unset the connection from the
schema_cache - we still want the cache just not the connection.
2019-06-05 16:37:08 -04:00
.github
actioncable
actionmailbox Unify to use 4 spaces indentation in CHANGELOGs [ci skip] 2019-06-05 05:53:49 +09:00
actionmailer
actionpack Unify to use 4 spaces indentation in CHANGELOGs [ci skip] 2019-06-05 05:53:49 +09:00
actiontext Unify to use 4 spaces indentation in CHANGELOGs [ci skip] 2019-06-05 05:53:49 +09:00
actionview Only clear cache when view paths are specified 2019-06-04 08:44:28 +09:00
activejob
activemodel Don't round off subseconds unless necessary 2019-05-28 22:50:36 +09:00
activerecord Move schema cache from connection to pool 2019-06-05 16:37:08 -04:00
activestorage Unify to use 4 spaces indentation in CHANGELOGs [ci skip] 2019-06-05 05:53:49 +09:00
activesupport Don't call listen with empty directory list 2019-06-03 18:57:36 -07:00
ci
guides 6.0 release notes: fix typo 2019-06-05 21:00:23 +12:00
railties Merge pull request #36416 from freeletics/fix-db-prepare 2019-06-05 10:31:52 -04:00
tasks
tools
.codeclimate.yml
.gitattributes
.gitignore
.rubocop.yml
.travis.yml
.yardopts
.yarnrc
Brewfile
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gemfile Bump bootsnap to a version with disables iseq_cache for Ruby 2.5 2019-04-26 12:55:28 +05:30
Gemfile.lock bundle update resque-scheduler to latest version 2019-05-08 18:05:44 +02:00
MIT-LICENSE
package.json
rails.gemspec
RAILS_VERSION
Rakefile
README.md
RELEASING_RAILS.md NPM -> npm [ci skip] 2019-05-12 12:00:03 +02:00
version.rb
yarn.lock Fix outdated yarn.lock 2019-04-25 14:27:11 +05:30

Welcome to Rails

What's Rails?

Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

Understanding the MVC pattern is key to understanding Rails. MVC divides your application into three layers: Model, View, and Controller, each with a specific responsibility.

Model layer

The Model layer represents the domain model (such as Account, Product, Person, Post, etc.) and encapsulates the business logic specific to your application. In Rails, database-backed model classes are derived from ActiveRecord::Base. Active Record allows you to present the data from database rows as objects and embellish these data objects with business logic methods. Although most Rails models are backed by a database, models can also be ordinary Ruby classes, or Ruby classes that implement a set of interfaces as provided by the Active Model module.

Controller layer

The Controller layer is responsible for handling incoming HTTP requests and providing a suitable response. Usually this means returning HTML, but Rails controllers can also generate XML, JSON, PDFs, mobile-specific views, and more. Controllers load and manipulate models, and render view templates in order to generate the appropriate HTTP response. In Rails, incoming requests are routed by Action Dispatch to an appropriate controller, and controller classes are derived from ActionController::Base. Action Dispatch and Action Controller are bundled together in Action Pack.

View layer

The View layer is composed of "templates" that are responsible for providing appropriate representations of your application's resources. Templates can come in a variety of formats, but most view templates are HTML with embedded Ruby code (ERB files). Views are typically rendered to generate a controller response, or to generate the body of an email. In Rails, View generation is handled by Action View.

Frameworks and libraries

Active Record, Active Model, Action Pack, and Action View can each be used independently outside Rails. In addition to that, Rails also comes with Action Mailer, a library to generate and send emails; Action Mailbox, a library to receive emails within a Rails application; Active Job, a framework for declaring jobs and making them run on a variety of queuing backends; Action Cable, a framework to integrate WebSockets with a Rails application; Active Storage, a library to attach cloud and local files to Rails applications; Action Text, a library to handle rich text content; and Active Support, a collection of utility classes and standard library extensions that are useful for Rails, and may also be used independently outside Rails.

Getting Started

  1. Install Rails at the command prompt if you haven't yet:

     $ gem install rails
    
  2. At the command prompt, create a new Rails application:

     $ rails new myapp
    

    where "myapp" is the application name.

  3. Change directory to myapp and start the web server:

     $ cd myapp
     $ rails server
    

    Run with --help or -h for options.

  4. Go to http://localhost:3000 and you'll see: "Yay! Youre on Rails!"

  5. Follow the guidelines to start developing your application. You may find the following resources handy:

Contributing

Code Triage Badge

We encourage you to contribute to Ruby on Rails! Please check out the Contributing to Ruby on Rails guide for guidelines about how to proceed. Join us!

Trying to report a possible security vulnerability in Rails? Please check out our security policy for guidelines about how to proceed.

Everyone interacting in Rails and its sub-projects' codebases, issue trackers, chat rooms, and mailing lists is expected to follow the Rails code of conduct.

Code Status

Build Status

License

Ruby on Rails is released under the MIT License.