Skip to content

Commit cb563a2

Browse files
Split code snippets by context [ci-skip]
This provides a stronger visual cue that the code in these snippets belongs in different contexts (e.g. separate files).
1 parent 71bc414 commit cb563a2

16 files changed

+95
-12
lines changed

guides/source/4_2_release_notes.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,15 +396,17 @@ Please refer to the [Changelog][railties] for detailed changes.
396396
* Introduced `Rails::Application.config_for` to load a configuration for the
397397
current environment.
398398
399-
```ruby
400-
# config/exception_notification.yml:
399+
```yaml
400+
# config/exception_notification.yml
401401
production:
402402
url: http://127.0.0.1:8080
403403
namespace: my_app_production
404404
development:
405405
url: http://localhost:3001
406406
namespace: my_app_development
407+
```
407408
409+
```ruby
408410
# config/environments/production.rb
409411
Rails.application.configure do
410412
config.middleware.use ExceptionNotifier, config_for(:exception_notification)

guides/source/5_0_release_notes.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,17 +96,20 @@ Some things that you can achieve with this:
9696
- Attributes do not need to be backed by a database column.
9797

9898
```ruby
99-
10099
# db/schema.rb
101100
create_table :store_listings, force: true do |t|
102101
t.decimal :price_in_cents
103102
t.string :my_string, default: "original default"
104103
end
104+
```
105105

106+
```ruby
106107
# app/models/store_listing.rb
107108
class StoreListing < ActiveRecord::Base
108109
end
110+
```
109111

112+
```ruby
110113
store_listing = StoreListing.new(price_in_cents: '10.1')
111114

112115
# before

guides/source/5_1_release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ class InvitationsMailer < ApplicationMailer
113113
mail subject: "#{@inviter.name} invited you to their Basecamp (#{@account.name})"
114114
end
115115
end
116+
```
116117

118+
```ruby
117119
InvitationsMailer.with(inviter: person_a, invitee: person_b)
118120
.account_invitation.deliver_later
119121
```

guides/source/action_cable_overview.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ Then you would create your own channel classes. For example, you could have a
188188
# app/channels/chat_channel.rb
189189
class ChatChannel < ApplicationCable::Channel
190190
end
191+
```
191192

193+
```ruby
192194
# app/channels/appearance_channel.rb
193195
class AppearanceChannel < ApplicationCable::Channel
194196
end

guides/source/action_mailer_basics.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ class ApplicationMailer < ActionMailer::Base
6464
default from: "[email protected]"
6565
layout 'mailer'
6666
end
67+
```
6768

69+
```ruby
6870
# app/mailers/user_mailer.rb
6971
class UserMailer < ApplicationMailer
7072
end
@@ -723,7 +725,7 @@ end
723725
724726
* You could use an `after_action` to do similar setup as a `before_action` but
725727
using instance variables set in your mailer action.
726-
728+
727729
* Using an `after_action` callback also enables you to override delivery method
728730
settings by updating `mail.delivery_method.settings`.
729731

guides/source/active_job_basics.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ module YourApp
196196
config.active_job.queue_name_prefix = Rails.env
197197
end
198198
end
199+
```
199200

201+
```ruby
200202
# app/jobs/guests_cleanup_job.rb
201203
class GuestsCleanupJob < ApplicationJob
202204
queue_as :low_priority
@@ -232,7 +234,9 @@ module YourApp
232234
config.active_job.queue_name_delimiter = '.'
233235
end
234236
end
237+
```
235238

239+
```ruby
236240
# app/jobs/guests_cleanup_job.rb
237241
class GuestsCleanupJob < ApplicationJob
238242
queue_as :low_priority
@@ -270,7 +274,9 @@ class ProcessVideoJob < ApplicationJob
270274
# Do process video
271275
end
272276
end
277+
```
273278

279+
```ruby
274280
ProcessVideoJob.perform_later(Video.last)
275281
```
276282

guides/source/active_record_postgresql.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,15 @@ that are supported by the PostgreSQL adapter.
3737
create_table :documents do |t|
3838
t.binary 'payload'
3939
end
40+
```
4041

42+
```ruby
4143
# app/models/document.rb
4244
class Document < ApplicationRecord
4345
end
46+
```
4447

48+
```ruby
4549
# Usage
4650
data = File.read(Rails.root + "tmp/output.pdf")
4751
Document.create payload: data
@@ -61,11 +65,15 @@ create_table :books do |t|
6165
end
6266
add_index :books, :tags, using: 'gin'
6367
add_index :books, :ratings, using: 'gin'
68+
```
6469

70+
```ruby
6571
# app/models/book.rb
6672
class Book < ApplicationRecord
6773
end
74+
```
6875

76+
```ruby
6977
# Usage
7078
Book.create title: "Brave New World",
7179
tags: ["fantasy", "fiction"],
@@ -348,12 +356,16 @@ create_table :comments, id: :uuid do |t|
348356
# t.belongs_to :post, type: :uuid
349357
t.references :post, type: :uuid
350358
end
359+
```
351360

361+
```ruby
352362
# app/models/post.rb
353363
class Post < ApplicationRecord
354364
has_many :comments
355365
end
366+
```
356367

368+
```ruby
357369
# app/models/comment.rb
358370
class Comment < ApplicationRecord
359371
belongs_to :post
@@ -502,11 +514,15 @@ create_table :documents do |t|
502514
end
503515

504516
add_index :documents, "to_tsvector('english', title || ' ' || body)", using: :gin, name: 'documents_idx'
517+
```
505518

519+
```ruby
506520
# app/models/document.rb
507521
class Document < ApplicationRecord
508522
end
523+
```
509524

525+
```ruby
510526
# Usage
511527
Document.create(title: "Cats and Dogs", body: "are nice!")
512528

guides/source/autoloading_and_reloading_constants.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,15 @@ require "sti_preload"
290290
class Shape < ApplicationRecord
291291
include StiPreload # Only in the root class.
292292
end
293+
```
293294

295+
```ruby
294296
# app/models/polygon.rb
295297
class Polygon < Shape
296298
end
299+
```
297300

301+
```ruby
298302
# app/models/triangle.rb
299303
class Triangle < Polygon
300304
end

guides/source/autoloading_and_reloading_constants_classic_mode.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,9 @@ module Blog
909909
"blog_"
910910
end
911911
end
912+
```
912913

914+
```ruby
913915
# app/models/blog/post.rb
914916
module Blog
915917
class Post < ApplicationRecord
@@ -949,11 +951,15 @@ these classes:
949951
# app/models/polygon.rb
950952
class Polygon < ApplicationRecord
951953
end
954+
```
952955

956+
```ruby
953957
# app/models/triangle.rb
954958
class Triangle < Polygon
955959
end
960+
```
956961

962+
```ruby
957963
# app/models/rectangle.rb
958964
class Rectangle < Polygon
959965
end
@@ -1157,7 +1163,9 @@ module BellX1
11571163
class FlightModel < FlightModel
11581164
end
11591165
end
1166+
```
11601167

1168+
```ruby
11611169
# app/models/bell_x1/aircraft.rb
11621170
module BellX1
11631171
class Aircraft
@@ -1211,11 +1219,15 @@ Given
12111219
# app/models/hotel.rb
12121220
class Hotel
12131221
end
1222+
```
12141223

1224+
```ruby
12151225
# app/models/image.rb
12161226
class Image
12171227
end
1228+
```
12181229

1230+
```ruby
12191231
# app/models/hotel/image.rb
12201232
class Hotel
12211233
class Image < Image
@@ -1267,7 +1279,9 @@ module Hotel
12671279
class Services
12681280
end
12691281
end
1282+
```
12701283

1284+
```ruby
12711285
# app/models/hotel/geo_location.rb
12721286
module Hotel
12731287
class GeoLocation

guides/source/configuring.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1697,7 +1697,7 @@ These configuration points are then available through the configuration object:
16971697
You can also use `Rails::Application.config_for` to load whole configuration files:
16981698
16991699
```yaml
1700-
# config/payment.yml:
1700+
# config/payment.yml
17011701
production:
17021702
environment: production
17031703
merchant_id: production_merchant_id
@@ -1709,7 +1709,9 @@ You can also use `Rails::Application.config_for` to load whole configuration fil
17091709
merchant_id: development_merchant_id
17101710
public_key: development_public_key
17111711
private_key: development_private_key
1712+
```
17121713
1714+
```ruby
17131715
# config/application.rb
17141716
module MyApp
17151717
class Application < Rails::Application

guides/source/i18n.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,9 @@ Add the missing translations into the translation dictionary files:
404404
en:
405405
hello_world: Hello world!
406406
hello_flash: Hello flash!
407+
```
407408

409+
```yaml
408410
# config/locales/pirate.yml
409411
pirate:
410412
hello_world: Ahoy World
@@ -472,7 +474,9 @@ provides a `number_to_currency` helper to handle the following case.
472474
# config/locales/en.yml
473475
en:
474476
currency: "$"
477+
```
475478

479+
```yaml
476480
# config/locales/es.yml
477481
es:
478482
currency: "€"
@@ -496,7 +500,9 @@ Proper abstraction is shown in the following example:
496500
# config/locales/en.yml
497501
en:
498502
product_price: "$%{price}"
503+
```
499504

505+
```yaml
500506
# config/locales/es.yml
501507
es:
502508
product_price: "%{price} €"

guides/source/layouts_and_rendering.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,15 +590,19 @@ In this application:
590590
Similar to the Layout Inheritance logic, if a template or partial is not found in the conventional path, the controller will look for a template or partial to render in its inheritance chain. For example:
591591

592592
```ruby
593-
# in app/controllers/application_controller
593+
# app/controllers/application_controller.rb
594594
class ApplicationController < ActionController::Base
595595
end
596+
```
596597

597-
# in app/controllers/admin_controller
598+
```ruby
599+
# app/controllers/admin_controller.rb
598600
class AdminController < ApplicationController
599601
end
602+
```
600603

601-
# in app/controllers/admin/products_controller
604+
```ruby
605+
# app/controllers/admin/products_controller.rb
602606
class Admin::ProductsController < AdminController
603607
def index
604608
end

guides/source/plugins.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ like yaffles.
261261
class Hickwall < ApplicationRecord
262262
acts_as_yaffle
263263
end
264+
```
264265

266+
```ruby
265267
# test/dummy/app/models/wickwall.rb
266268

267269
class Wickwall < ApplicationRecord
@@ -284,7 +286,9 @@ module Yaffle
284286
end
285287
end
286288
end
289+
```
287290

291+
```ruby
288292
# test/dummy/app/models/application_record.rb
289293

290294
class ApplicationRecord < ActiveRecord::Base
@@ -340,7 +344,9 @@ module Yaffle
340344
end
341345
end
342346
end
347+
```
343348

349+
```ruby
344350
# test/dummy/app/models/application_record.rb
345351

346352
class ApplicationRecord < ActiveRecord::Base
@@ -413,7 +419,9 @@ module Yaffle
413419
end
414420
end
415421
end
422+
```
416423

424+
```ruby
417425
# test/dummy/app/models/application_record.rb
418426

419427
class ApplicationRecord < ActiveRecord::Base

guides/source/routing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,9 @@ class Video < ApplicationRecord
12261226
identifier
12271227
end
12281228
end
1229+
```
12291230

1231+
```ruby
12301232
video = Video.find_by(identifier: "Roman-Holiday")
12311233
edit_video_path(video) # => "/videos/Roman-Holiday/edit"
12321234
```
@@ -1247,7 +1249,9 @@ Rails.application.routes.draw do
12471249

12481250
draw(:admin) # Will load another route file located in `config/routes/admin.rb`
12491251
end
1252+
```
12501253

1254+
```ruby
12511255
# config/routes/admin.rb
12521256

12531257
namespace :admin do

0 commit comments

Comments
 (0)