Core Modules
Active Record
--skip-active-record [-O]
Cable
--skip-action-cable [-C]
# app/channels/application_cable/channel.rb
module ApplicationCable
class Channel < ActionCable::Channel::Base
end
end
# app/channels/application_cable/connection.rb
module ApplicationCable
class Connection < ActionCable::Connection::Base
end
end
// app/javascript/channels/consumer.js
import { createConsumer } from '@rails/actioncable'
export default createConsumer()
// app/javascript/channels/index.js
const channels = require.context('.', true, /_channel\.js$/)
channels.keys().forEach(channels)
// app/javascript/packs/application.js
require('channels')
# config/application.rb
require 'action_cable/engine'
# 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
# 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
# test/channels/application_cable/connection_test.rb
require 'test_helper'
class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase
end
# Gemfile
gem 'redis', '~> 4.0'
// package.json
{
"dependencies": {
"@rails/actioncable": "^6.0.0"
}
}
Mailer
--skip-action-mailer [-M]
ActionMailer will add a folder: test/mailers
# app/mailers/application_mailer.rb
class ApplicationMailer < ActionMailer::Base
default from: 'from@example.com'
layout 'mailer'
end
<!-- 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 %>
# config/application.rb
require 'action_mailer/railtie'
# config/environments/development.rb
class Application < Rails::Application
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_caching = false
end
# config/environments/production.rb
class Application < Rails::Application
config.action_mailer.perform_caching = false
# config.action_mailer.raise_delivery_errors = false
end
# 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
ActionMailbox depends on ActiveStorage
# config/application.rb
# require 'active_storage/engine'
require 'action_mailbox/engine'
Storage
--skip-active-storage
ActiveStorage will add two folders: storage
and tmp/storage
// app/javascript/packs/application.js
require('@rails/activestorage').start()
ActionMailbox and ActionText depend on ActiveStorage
# config/application.rb
require 'active_storage/engine'
# require 'action_mailbox/engine'
# require 'action_text/engine'
# config/environments/development.rb
class Application < Rails::Application
config.active_storage.service = :local
end
# config/environments/production.rb
class Application < Rails::Application
config.active_storage.service = :local
end
# config/environments/test.rb
class Application < Rails::Application
config.active_storage.service = :test
end
# config/storage.yml
local:
service: Disk
root: <%= Rails.root.join('storage') %>
test:
service: Disk
root: <%= Rails.root.join('tmp/storage') %>
# .gitignore
/storage/*
!/storage/.keep
# Gemfile
# gem 'image_processing', '~> 1.2'
// package.json
{
"dependencies": {
"@rails/activestorage": "^6.0.0"
}
}
Text
--skip-action-text
ActionText depends on ActiveStorage
# config/application.rb
# require 'active_storage/engine'
require 'action_text/engine'
Last updated