# Core Modules

## Active Record

`--skip-active-record [-O]`

## Cable

`--skip-action-cable [-C]`

```ruby
# app/channels/application_cable/channel.rb

module ApplicationCable
  class Channel < ActionCable::Channel::Base
  end
end
```

```ruby
# app/channels/application_cable/connection.rb

module ApplicationCable
  class Connection < ActionCable::Connection::Base
  end
end
```

```javascript
// app/javascript/channels/consumer.js

import { createConsumer } from '@rails/actioncable'

export default createConsumer()
```

```javascript
// app/javascript/channels/index.js

const channels = require.context('.', true, /_channel\.js$/)

channels.keys().forEach(channels)
```

```javascript
// app/javascript/packs/application.js

require('channels')
```

```ruby
# config/application.rb

require 'action_cable/engine'
```

```yaml
# config/cable.yml

development:
  adapter: async

test:
  adapter: test

production:
  adapter: redis
  url: <%= ENV.fetch("REDIS_URL") { 'redis://localhost:6379/1' } %>
  channel_prefix: my_app_production
```

```ruby
# config/environments/production.rb

class Application < Rails::Application
  # Mount Action Cable outside main process or domain.
  # config.action_cable.mount_path = nil
  # config.action_cable.url = 'wss://example.com/cable'
  # config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]
end
```

```ruby
# test/channels/application_cable/connection_test.rb

require 'test_helper'

class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
end
```

```ruby
# Gemfile

gem 'redis', '~> 4.0'
```

```javascript
// package.json

{
  "dependencies": {
    "@rails/actioncable": "^6.0.0"
  }
}
```

## Mailer

`--skip-action-mailer [-M]`

{% hint style="info" %}
ActionMailer will add a folder: `test/mailers`
{% endhint %}

```ruby
# app/mailers/application_mailer.rb

class ApplicationMailer < ActionMailer::Base
  default from: 'from@example.com'
  layout 'mailer'
end
```

```markup
<!-- app/views/layouts/mailer.html.erb -->

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style>
    </style>
  </head>
  <body>
    <%= yield %>
  </body>
</html>
```

```
# app/views/layouts/mailer.text.erb

<%= yield %>
```

```ruby
# config/application.rb

require 'action_mailer/railtie'
```

```ruby
# config/environments/development.rb

class Application < Rails::Application
  config.action_mailer.raise_delivery_errors = false
  config.action_mailer.perform_caching = false
end
```

```ruby
# config/environments/production.rb

class Application < Rails::Application
  config.action_mailer.perform_caching = false
  # config.action_mailer.raise_delivery_errors = false
end
```

```ruby
# config/environments/test.rb

class Application < Rails::Application
  config.action_mailer.perform_caching = false
  config.action_mailer.delivery_method = :test
end
```

## Mailbox

`--skip-action-mailbox`

{% hint style="danger" %}
ActionMailbox depends on ActiveStorage
{% endhint %}

```ruby
# config/application.rb

# require 'active_storage/engine'
require 'action_mailbox/engine'
```

## Storage

`--skip-active-storage`

{% hint style="info" %}
ActiveStorage will add two folders: `storage` and `tmp/storage`
{% endhint %}

```javascript
// app/javascript/packs/application.js

require('@rails/activestorage').start()
```

{% hint style="danger" %}
ActionMailbox and ActionText depend on ActiveStorage
{% endhint %}

```ruby
# config/application.rb

require 'active_storage/engine'
# require 'action_mailbox/engine'
# require 'action_text/engine'
```

```ruby
# config/environments/development.rb

class Application < Rails::Application
  config.active_storage.service = :local
end
```

```ruby
# config/environments/production.rb

class Application < Rails::Application
  config.active_storage.service = :local
end
```

```ruby
# config/environments/test.rb

class Application < Rails::Application
  config.active_storage.service = :test
end
```

```yaml
# config/storage.yml

local:
  service: Disk
  root: <%= Rails.root.join('storage') %>

test:
  service: Disk
  root: <%= Rails.root.join('tmp/storage') %>
```

```
# .gitignore

/storage/*
!/storage/.keep
```

```ruby
# Gemfile

# gem 'image_processing', '~> 1.2'
```

```javascript
// package.json

{
  "dependencies": {
    "@rails/activestorage": "^6.0.0"
  }
}
```

## Text

`--skip-action-text`

{% hint style="danger" %}
ActionText depends on ActiveStorage
{% endhint %}

```ruby
# config/application.rb

# require 'active_storage/engine'
require 'action_text/engine'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.alistairtweed.com/rails/minimal-rails/core-modules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
