-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrails_gems.html
More file actions
587 lines (577 loc) · 38.6 KB
/
rails_gems.html
File metadata and controls
587 lines (577 loc) · 38.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
<!doctype html>
<html dir="ltr" lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Some Gems for Rails — Ruby on Rails Guides</title>
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" data-turbo-track="reload">
<link rel="stylesheet" type="text/css" href="stylesheets/print.css" media="print">
<link rel="stylesheet" type="text/css" href="stylesheets/highlight.css" data-turbo-track="reload">
<link rel="icon" href="images/backend-development.svg" sizes="any">
<script src="javascripts/@hotwired--turbo.js" data-turbo-track="reload"></script>
<script src="javascripts/clipboard.js" data-turbo-track="reload"></script>
<script src="javascripts/guides.js" data-turbo-track="reload"></script>
<meta property="og:title" content="Some Gems for Rails — Ruby on Rails Guides" />
<meta name="description" content="Some Gems for RailsThis guide lists a few valuable gems for your first Rails Project.After reading this guide you will understand how gems are installed understand how bundler handles dependencies be able to configure the gems you use be able to deliberately chose version numbers for your gems know a few intresting gems for your next rails project" />
<meta property="og:description" content="Some Gems for RailsThis guide lists a few valuable gems for your first Rails Project.After reading this guide you will understand how gems are installed understand how bundler handles dependencies be able to configure the gems you use be able to deliberately chose version numbers for your gems know a few intresting gems for your next rails project" />
<meta property="og:locale" content="en_US" />
<meta property="og:site_name" content="Textbook Backend Developemnt" />
<meta property="og:image" content="images/backend-development.svg" />
<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="#2e56e9">
</head>
<body class="guide">
<header id="page_header">
<div class="wrapper clearfix">
<nav id="feature_nav">
<div class="header-logo">
<a href="/">Backend Development</a>
</div>
<ul class="nav">
<li><a class="nav-item" id="home_nav" href="/">Home</a></li>
<li class="guides-index guides-index-large">
<a href="index.html" id="guidesMenu" class="guides-index-item nav-item">Index</a>
<div id="guides" class="clearfix" style="display: none;">
<hr />
<dl class="guides-section-container">
<div class="guides-section">
<dt>Ruby on Rails</dt>
<dd><a href="ruby_commandline.html">Ruby Commandline</a></dd>
<dd><a href="rails_database_and_model.html">Models and ActiveRecord</a></dd>
<dd><a href="rails_db.html">Database and Migrations</a></dd>
<dd><a href="rails_associations_and_validations.html">Associations and Validations</a></dd>
<dd><a href="rails_view_and_controller.html">Routing, View and Controller</a></dd>
<dd><a href="rails_authentication.html">Simple Authentication</a></dd>
<dd><a href="assets_and_import_map.html">The Asset Pipeline and Importmaps</a></dd>
<dd><a href="testing.html">Getting started with Testing</a></dd>
<dd><a href="refactoring_rails.html">Refactoring Rails</a></dd>
<dd><a href="deploy-to-paas.html">Deploy to PAAS</a></dd>
<dd><a href="rails_gems.html">Ruby Gems for your Rails Project</a></dd>
<dd><a href="deploying_rails.html">Deploying Rails</a></dd>
</div>
<div class="guides-section">
<dt>Ruby on Rails - Advanced Topics</dt>
<dd><a href="deploy-to-paas.html">Deploy to PAAS</a></dd>
<dd><a href="rest-api.html">REST API</a></dd>
<dd><a href="graphql-api.html">GraphQL API</a></dd>
<dd><a href="rails_websockets.html">Websocket in Rails</a></dd>
<dd><a href="jobs_and_tasks.html">Jobs and Tasks in Rails</a></dd>
<dd><a href="rails_security.html">Rails Security</a></dd>
</div>
<div class="guides-section">
<dt>Overarching Concerns</dt>
<dd><a href="issue.html">Issue Lifecycle</a></dd>
<dd><a href="security.html">Security</a></dd>
<dd><a href="adv_authentication.html">Advanced Authentication</a></dd>
<dd><a href="caching.html">Caching</a></dd>
<dd><a href="advanced_testing.html">Advanced Testing</a></dd>
<dd><a href="internationalization.html">Internationalization (I18n)</a></dd>
<dd><a href="git_rebasing.html">Git Rebasing</a></dd>
</div>
<div class="guides-section">
<dt>Nodes.js</dt>
<dd><a href="node_vs_rails.html">Node vs. Rails</a></dd>
<dd><a href="node_basics.html">Node Basics</a></dd>
<dd><a href="node_websockets.html">Node Websockets</a></dd>
<dd><a href="node_express.html">Node Web App</a></dd>
<dd><a href="node_cluster.html">Scaling Node</a></dd>
</div>
<div class="guides-section">
<dt>Next.js</dt>
<dd><a href="nextjs.html">Next.js</a></dd>
</div>
</dl>
</div>
</li>
<li class="guides-index guides-index-small">
<select class="guides-index-item nav-item">
<option value="index.html">Index</option>
<optgroup label="Ruby on Rails">
<option value="ruby_commandline.html">Ruby Commandline</option>
<option value="rails_database_and_model.html">Models and ActiveRecord</option>
<option value="rails_db.html">Database and Migrations</option>
<option value="rails_associations_and_validations.html">Associations and Validations</option>
<option value="rails_view_and_controller.html">Routing, View and Controller</option>
<option value="rails_authentication.html">Simple Authentication</option>
<option value="assets_and_import_map.html">The Asset Pipeline and Importmaps</option>
<option value="testing.html">Getting started with Testing</option>
<option value="refactoring_rails.html">Refactoring Rails</option>
<option value="deploy-to-paas.html">Deploy to PAAS</option>
<option value="rails_gems.html">Ruby Gems for your Rails Project</option>
<option value="deploying_rails.html">Deploying Rails</option>
</optgroup>
<optgroup label="Ruby on Rails - Advanced Topics">
<option value="deploy-to-paas.html">Deploy to PAAS</option>
<option value="rest-api.html">REST API</option>
<option value="graphql-api.html">GraphQL API</option>
<option value="rails_websockets.html">Websocket in Rails</option>
<option value="jobs_and_tasks.html">Jobs and Tasks in Rails</option>
<option value="rails_security.html">Rails Security</option>
</optgroup>
<optgroup label="Overarching Concerns">
<option value="issue.html">Issue Lifecycle</option>
<option value="security.html">Security</option>
<option value="adv_authentication.html">Advanced Authentication</option>
<option value="caching.html">Caching</option>
<option value="advanced_testing.html">Advanced Testing</option>
<option value="internationalization.html">Internationalization (I18n)</option>
<option value="git_rebasing.html">Git Rebasing</option>
</optgroup>
<optgroup label="Nodes.js">
<option value="node_vs_rails.html">Node vs. Rails</option>
<option value="node_basics.html">Node Basics</option>
<option value="node_websockets.html">Node Websockets</option>
<option value="node_express.html">Node Web App</option>
<option value="node_cluster.html">Scaling Node</option>
</optgroup>
<optgroup label="Next.js">
<option value="nextjs.html">Next.js</option>
</optgroup>
</select>
</li>
</ul>
</nav>
</div>
</header>
<hr class="hide" />
<section id="feature">
<div class="wrapper">
<h1>Some Gems for Rails</h1><p>This guide lists a few valuable gems for
your first Rails Project.</p><p>After reading this guide you will</p>
<ul>
<li>understand how gems are installed</li>
<li>understand how bundler handles dependencies</li>
<li>be able to configure the gems you use</li>
<li>be able to deliberately chose version numbers for your gems</li>
<li>know a few intresting gems for your next rails project</li>
</ul>
<nav id="subCol">
<h3 class="chapter">
<picture>
<!-- 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
</h3>
<ol class="chapters">
<li><a href="#gems-and-bundler">Gems and Bundler</a>
<ul>
<li><a href="#dependencies">dependencies</a></li>
<li><a href="#gems">gems</a></li>
<li><a href="#dependency-hell">dependency hell</a></li>
<li><a href="#bundler-saves-us">bundler saves us</a></li>
<li><a href="#defining-versions">defining versions</a></li>
<li><a href="#gems-and-rails">gems and rails</a></li>
</ul></li>
<li><a href="#some-gems">Some Gems</a>
<ul>
<li><a href="#file-upload">File Upload</a></li>
<li><a href="#authentication">Authentication</a></li>
<li><a href="#permalinks">Permalinks</a></li>
<li><a href="#parsing-xml-and-html">Parsing xml and html</a></li>
<li><a href="#let-users-format-their-texts">Let Users format their Texts</a></li>
<li><a href="#pagination">Pagination</a></li>
<li><a href="#filter">Filter</a></li>
<li><a href="#ordered-lists">Ordered Lists</a></li>
<li><a href="#workflows">Workflows</a></li>
<li><a href="#search">Search</a></li>
<li><a href="#activity-stream">Activity Stream</a></li>
<li><a href="#payment">Payment</a></li>
<li><a href="#admin-backend">Admin Backend</a></li>
<li><a href="#sending-mail-and-other-notifications">Sending Mail and other Notifications</a></li>
<li><a href="#http-requests">HTTP Requests</a></li>
<li><a href="#using-apis">Using APIs</a></li>
<li><a href="#geo-information-geocoding">Geo Information, Geocoding</a></li>
<li><a href="#pdf-excel-csv">PDF, Excel, csv, ...</a></li>
<li><a href="#one-rails-code-for-many-sites-tenants">One Rails Code for Many Sites ("Tenants")</a></li>
<li><a href="#tracking-users">Tracking Users</a></li>
<li><a href="#testing">Testing</a></li>
<li><a href="#understanding-your-code-better">Understanding your Code better</a></li>
</ul></li>
<li><a href="#ressources">Ressources</a></li>
</ol>
</nav>
<hr>
</div>
</section>
<main id="container">
<div class="wrapper">
<div id="mainCol">
<div class='slide'>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-0' href='slides_rails_gems.html#/0'>◻</a></p>
<h2 id="gems-and-bundler"><a class="anchorlink" href="#gems-and-bundler"><span>1</span> Gems and Bundler</a></h2></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-1' href='slides_rails_gems.html#/1'>◻</a></p>
<h3 id="dependencies"><a class="anchorlink" href="#dependencies"><span>1.1</span> dependencies</a></h3><p>Reusing code is a determining factor when it comes to the productivity of a programmer.
We refer to other people's code we reuse as a "dependency" since
our program depends on it.</p><p>Using a dependency always carries a risk.</p><p><img src="images/dependency.png" alt=""></p><p>Visualisation of modern software development in <a href="https://xkcd.com/2347/">xkcd</a></p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-2' href='slides_rails_gems.html#/2'>◻</a></p>
<h3 id="gems"><a class="anchorlink" href="#gems"><span>1.2</span> gems</a></h3><p>In Ruby the unit of reuse is called a <code>gem</code>. <code>rubygems</code> is the package manager for ruby,
it let's you install gems on your system.</p><p>A gem has a name (e.g. <code>rake</code>) and a version number (e.g. <code>10.4.2</code>).
It can be written in plain ruby or sometimes in ruby and c. Many gems
depend on system libraries that need to be installed before the gem can
be installed. For example the <a href="https://rubygems.org/gems/rmagick/versions/2.15.4">rmagick</a>
gem for image manipulation needs the library <code>ImageMagick</code>.</p><p>So most of the time installing a gem is as simple as</p><div class="interstitial code">
<pre><code class="highlight console"><span class="gp">></span><span class="w"> </span><span class="nb">gem install </span>rails_best_practices
<span class="go">Successfully installed rails_best_practices-1.15.7
Parsing documentation for rails_best_practices-1.15.7
Installing ri documentation for rails_best_practices-1.15.7
Done installing documentation for rails_best_practices after 2 seconds
1 gem installed
</span></code></pre>
<button class="clipboard-button" data-clipboard-text="">Copy</button>
</div>
<p>But sometimes you have to do other installations first.
On your development machine this might look like this:</p><div class="interstitial code">
<pre><code class="highlight console"><span class="gp">#</span><span class="w"> </span><span class="nb">install node </span>on a mac
<span class="gp">></span><span class="w"> </span><span class="nb">brew install </span>nodejs
<span class="gp">></span><span class="w"> </span><span class="nb">gem install </span>uglifier
</code></pre>
<button class="clipboard-button" data-clipboard-text="">Copy</button>
</div>
<p>Sometimes you need to set include paths when compiling the c-part of the gem, e.g.:</p><div class="interstitial code">
<pre><code class="highlight console"><span class="gp">></span><span class="w"> </span><span class="nb">gem install </span>eventmachine
<span class="go">... error messages ...
In file included from binder.cpp:20:
./project.h:116:10: fatal error: 'openssl/ssl.h' file not found
</span><span class="gp">#</span>include <openssl/ssl.h>
<span class="go"> ^
</span><span class="gp">></span><span class="w"> </span><span class="nb">brew install </span>openssl
<span class="gp">></span><span class="w"> </span><span class="nb">gem install </span>eventmachine <span class="nt">--</span> <span class="nt">--with-cppflags</span><span class="o">=</span><span class="nt">-I</span>/usr/local/opt/openssl/include
</code></pre>
<button class="clipboard-button" data-clipboard-text="">Copy</button>
</div>
<p>In production you probably have to deal with Linux, and you
may not have the right permissions to install system libraries.
A typical example would be:</p><div class="interstitial code">
<pre><code class="highlight shell"><span class="nv">$dev</span><span class="o">></span> ssh my.production.machine
<span class="nv">$production</span><span class="o">></span> <span class="nb">sudo </span>apt-get <span class="nb">install </span>libmagick++-dev
<span class="nv">$production</span><span class="o">></span> <span class="nb">gem install </span>rmagick
<span class="nv">$production</span><span class="o">></span> <span class="nb">gem install </span>paperclip
</code></pre>
<button class="clipboard-button" data-clipboard-text="$dev> ssh my.production.machine
$production> sudo apt-get install libmagick++-dev
$production> gem install rmagick
$production> gem install paperclip
">Copy</button>
</div>
<p>Now that you have installed the gem once by hand
you can be sure that it can also be reinstalled by bundler.</p><p>See also:</p>
<ul>
<li><a href="https://guides.rubygems.org/what-is-a-gem/">what is a gem</a></li>
<li>find <a href="https://rubygems.org/stats">150.000 gems</a> at <a href="https://rubygems.org/">rubygems.org</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-3' href='slides_rails_gems.html#/3'>◻</a></p>
<h3 id="dependency-hell"><a class="anchorlink" href="#dependency-hell"><span>1.3</span> dependency hell</a></h3><p>For a rails project you will be using a lot of gems. This will lead
to two problems:</p>
<ol>
<li>dependency resolution: gem A depends on version 1.1 of gem C, while gem B wants at least version 1.5. You need to find the right version of every gem in your project that actually fits together</li>
<li>different installation: when deploying to a production server, or even just when shareing code with other developers you need to make sure that the same constellation of gems and versions is used on every machine</li>
</ol>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-4' href='slides_rails_gems.html#/4'>◻</a></p>
<h3 id="bundler-saves-us"><a class="anchorlink" href="#bundler-saves-us"><span>1.4</span> bundler saves us</a></h3><p><img src="images/bundler-small.png" alt="bundler"></p><p>Bundler is the name of the tool that saves us from dependency hell.
Bundler is itself a gem, so you install it with <code>gem install bundler</code>.
Beware: the command you will be using called <code>bundle</code>, not bundler.</p><p>There is how it works: In every ruby project you write
a <code>Gemfile</code> in which you define which gems and (to a certain degree) which versions you want.
When you run <code>bundle install</code> bundler will:</p>
<ul>
<li>read the Gemfile,</li>
<li>pick out compatible versions of all the gems (if possible),</li>
<li>install all these gems</li>
<li>write <code>Gemfile.lock</code></li>
</ul>
<p>The lock-file contains a complete list of all the gems necessary for
your project, and their version numbers. These are now locked down,
and will not change!</p><p>When deploying to a new development machine or the production server,
you run <code>bundle install</code> and the exact same versions are now installed.</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-5' href='slides_rails_gems.html#/5'>◻</a></p>
<h3 id="defining-versions"><a class="anchorlink" href="#defining-versions"><span>1.5</span> defining versions</a></h3><p>In the Gemfile you can specify which versions should be used.
But don't overdo it! Bundler does a good job picking versions,
if you specify every version number by hand you are doing too much work.</p><p>Some examples of the different ways of specifying version number and source:</p><div class="interstitial code">
<pre><code class="highlight ruby"><span class="c1"># Gemfile</span>
<span class="n">source</span> <span class="s1">'https://rubygems.org'</span>
<span class="n">ruby</span> <span class="s1">'2.3.1'</span>
<span class="n">gem</span> <span class="s1">'rails'</span><span class="p">,</span> <span class="s1">'~> 5.0.0'</span><span class="p">,</span> <span class="s1">'>= 5.0.0.1'</span>
<span class="n">gem</span> <span class="s1">'sqlite3'</span>
<span class="n">gem</span> <span class="s1">'puma'</span><span class="p">,</span> <span class="s1">'~> 3.0'</span>
</code></pre>
<button class="clipboard-button" data-clipboard-text="# Gemfile
source 'https://rubygems.org'
ruby '2.3.1'
gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'sqlite3'
gem 'puma', '~> 3.0'
">Copy</button>
</div>
<p>The arrow <code>~></code> will only allow an increase in the
last (right most) number, so <code>~> 5.0.0</code> does allow <code>5.0.0.7</code> but not <code>5.0.1</code> or <code>5.1</code>.
This is called a pessimistic version constraint, read more about
it in <a href="https://guides.rubygems.org/patterns/#pessimistic-version-constraint">the rubygem documentation</a>.</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-6' href='slides_rails_gems.html#/6'>◻</a></p>
<h3 id="gems-and-rails"><a class="anchorlink" href="#gems-and-rails"><span>1.6</span> gems and rails</a></h3><p>The configuration for a gem is found in the initializer directory,
for example for <code>devise</code> the configuration file would be <code>config/initializers/devise.rb</code>.</p><p>A gem may install new generators for rails, run <code>rails generate</code> to see a list
of available generators.</p><p>A gem may install rake tasks, run <code>rails -T</code> to see a list.</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-7' href='slides_rails_gems.html#/7'>◻</a></p>
<h2 id="some-gems"><a class="anchorlink" href="#some-gems"><span>2</span> Some Gems</a></h2><p>This list was inspired by the <a href="https://blog.railsrumble.com/2016/01/15/gem-teardown/">Rails Rumble gem teardown</a> and
<a href="http://codebeerstartups.com/must-have-gems-for-development-machine-in-ruby-on-rails/">coodbeerstartups "Must Have Gems for Development Machine in Ruby on Rails "</a>.</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-8' href='slides_rails_gems.html#/8'>◻</a></p>
<h3 id="file-upload"><a class="anchorlink" href="#file-upload"><span>2.1</span> File Upload</a></h3><p>File Upload has been integrated into Rails 5 with
<a href="https://edgeguides.rubyonrails.org/active_storage_overview.html">ActiveStorage</a>, there is no need to use
<a href="https://github.com/carrierwaveuploader/carrierwave">carrierwave</a> or
or
<a href="https://github.com/thoughtbot/paperclip">paperclip</a>
and more.</p><p>You can resize or crop your images
automatically. This is traditionally done with
the libraries <a href="https://www.imagemagick.org/">ImageMagick</a> or
<a href="https://libvips.github.io/libvips/">vips</a></p><p>There are ruby gem for those libaries that install precompiled versions:</p>
<ul>
<li>gem <a href="https://github.com/rmagick/rmagick">rmagick</a> image processing with image magick</li>
<li>gem <a href="https://github.com/ioquatix/vips">vips</a></li>
</ul>
<p>and a high level gem that handles both libraries:</p>
<ul>
<li>gem <a href="https://github.com/janko/image_processing">image-processing</a></li>
</ul>
<p>You might also want to know how to use ImageMagick on the UNIX commandline:</p>
<ul>
<li>command line tool <a href="https://www.imagemagick.org/script/convert.php">convert</a> to convert to different formats and</li>
<li>command line tool <a href="https://www.imagemagick.org/script/mogrify.php">mogrify</a> to resize, blur, crop, draw on, flip, join, ... an image and overwrite it.</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-9' href='slides_rails_gems.html#/9'>◻</a></p>
<h3 id="authentication"><a class="anchorlink" href="#authentication"><span>2.2</span> Authentication</a></h3>
<ul>
<li>gem <a href="https://github.com/plataformatec/devise">devise</a> for login,</li>
<li>gem <a href="https://github.com/intridea/omniauth">omniauth</a> to integrate authentication methods,</li>
<li><p>gem <a href="https://github.com/CanCanCommunity/cancancan">cancancan</a> if you need roles and permissions.</p></li>
<li><p>gem <a href="https://github.com/bitzesty/devise_zxcvbn">devise_zxcvbn</a> to reject weak passwords (port of <a href="https://dropbox.tech/security/zxcvbn-realistic-password-strength-estimation">zxcvbn</a>).</p></li>
<li><p>gem <a href="https://github.com/michaelbanfield/devise-pwned_password">devise-pwned_password</a></p></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-10' href='slides_rails_gems.html#/10'>◻</a></p>
<h3 id="permalinks"><a class="anchorlink" href="#permalinks"><span>2.3</span> Permalinks</a></h3><p>You don't want the database keys to be visible in your URLs? Use Friendly IDs instead:</p>
<ul>
<li>gem <a href="https://github.com/norman/friendly_id">friendlyid</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-11' href='slides_rails_gems.html#/11'>◻</a></p>
<h3 id="parsing-xml-and-html"><a class="anchorlink" href="#parsing-xml-and-html"><span>2.4</span> Parsing xml and html</a></h3>
<ul>
<li>gem <a href="https://www.nokogiri.org/">nokogiri</a></li>
</ul>
<p>(this is also used by capybara)</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-12' href='slides_rails_gems.html#/12'>◻</a></p>
<h3 id="let-users-format-their-texts"><a class="anchorlink" href="#let-users-format-their-texts"><span>2.5</span> Let Users format their Texts</a></h3><p>Letting users enter HTML is a dangerous idea - it's really hard to
avoid the security problems. An alternative is to let them enter
a simpler markup language, like <a href="https://en.wikipedia.org/wiki/Markdown">Markdown</a>.
You store the markdown in your database, and convert it to HTML when displayed using a gem:</p>
<ul>
<li>gem <a href="https://github.com/github/markup">github-markup</a></li>
</ul>
<p>Or use the builtin editor (since rails 6):</p>
<ul>
<li><a href="https://edgeguides.rubyonrails.org/action_text_overview.html">ActionText</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-13' href='slides_rails_gems.html#/13'>◻</a></p>
<h3 id="pagination"><a class="anchorlink" href="#pagination"><span>2.6</span> Pagination</a></h3><p>Do you need to displaying a lot of items? Use a pagination gem
to go through them page by page:</p>
<ul>
<li>gem <a href="https://github.com/amatsuda/kaminari">kaminari</a>, <a href="http://railscasts.com/episodes/254-pagination-with-kaminari?view=asciicast">asciicast about it</a></li>
<li>other gems in <a href="https://www.ruby-toolbox.com/categories/pagination">category pagination</a> of the ruby toolbox</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-14' href='slides_rails_gems.html#/14'>◻</a></p>
<h3 id="filter"><a class="anchorlink" href="#filter"><span>2.7</span> Filter</a></h3><p>You need to filter objects shown by the index action?</p>
<ul>
<li>gem <a href="https://github.com/procore/sift">sift</a> can be used in APIs and full rails apps</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-15' href='slides_rails_gems.html#/15'>◻</a></p>
<h3 id="ordered-lists"><a class="anchorlink" href="#ordered-lists"><span>2.8</span> Ordered Lists</a></h3>
<ul>
<li>gem <a href="https://github.com/brendon/acts_as_list">acts_as_list</a></li>
<li>gem <a href="https://github.com/brendon/ranked-model">ranked_model</a></li>
</ul>
<p>are the two active gems in <a href="https://www.ruby-toolbox.com/categories/Active_Record_Sortables">Active Record Sortables</a> of the ruby toolbox</p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-16' href='slides_rails_gems.html#/16'>◻</a></p>
<h3 id="workflows"><a class="anchorlink" href="#workflows"><span>2.9</span> Workflows</a></h3><p>state machines are an importante pattern for
representing workflows:</p>
<ul>
<li><a href="https://blog.appsignal.com/2022/06/22/state-machines-in-ruby-an-introduction.html">state_machine gems</a> intro on AppSignal Blog</li>
<li>gem <a href="https://github.com/gocardless/statesman">statesman</a></li>
</ul>
<p>With paper trail you can keep track who changed a model:</p>
<ul>
<li><a href="https://github.com/paper-trail-gem/paper_trail">paper trail</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-17' href='slides_rails_gems.html#/17'>◻</a></p>
<h3 id="search"><a class="anchorlink" href="#search"><span>2.10</span> Search</a></h3><p>You need to search in more than just one attribute of your
model? use a search gem:</p>
<ul>
<li>gem <a href="https://github.com/activerecord-hackery/ransack">ransack</a> for building search fields</li>
<li>gem <a href="https://github.com/Casecommons/pg_search">pg_search</a> uses postgresql's fulltext search</li>
<li>gem <a href="https://github.com/ankane/searchkick">searchkick</a> uses elasticsearch with many more options for fulltext search, e.g. for misspellings</li>
<li>other gems in <a href="https://www.ruby-toolbox.com/categories/rails_search">category rails_search</a> of the ruby toolbox</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-18' href='slides_rails_gems.html#/18'>◻</a></p>
<h3 id="activity-stream"><a class="anchorlink" href="#activity-stream"><span>2.11</span> Activity Stream</a></h3><p>If you want to give users an overview of what happened recently
you can use an activity stream, similar to what you see in facebook.</p><p><img src="images/gem-activity.png" alt="activity stream example"></p>
<ul>
<li>gem <a href="https://github.com/pokonski/public_activity">public_activity</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-19' href='slides_rails_gems.html#/19'>◻</a></p>
<h3 id="payment"><a class="anchorlink" href="#payment"><span>2.12</span> Payment</a></h3><p>Recieve Money with <a href="https://github.com/activemerchant/active_merchant">ActiveMerchant</a></p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-20' href='slides_rails_gems.html#/20'>◻</a></p>
<h3 id="admin-backend"><a class="anchorlink" href="#admin-backend"><span>2.13</span> Admin Backend</a></h3><p>Quickly create a Backend for editing the data in your database:</p><p><img src="images/avo.jpg" alt="Avo Screenshot"></p>
<ul>
<li>gem <a href="https://avohq.io/">avo</a></li>
<li>gem <a href="https://activeadmin.info/">activeadmin</a></li>
<li>gem <a href="https://github.com/sferik/rails_admin">rails_admin</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-21' href='slides_rails_gems.html#/21'>◻</a></p>
<h3 id="sending-mail-and-other-notifications"><a class="anchorlink" href="#sending-mail-and-other-notifications"><span>2.14</span> Sending Mail and other Notifications</a></h3><p>To send mail from Rails use <a href="https://guides.rubyonrails.org/action_mailer_basics.html">ActionMailer</a>.</p><p>To see the generated mails in your web browser <em>instead</em> of sending them, use the gem <a href="https://github.com/ryanb/letter_opener">letter_opener</a></p><p>To receive Mail use <a href="https://edgeguides.rubyonrails.org/action_mailbox_basics.html">ActionMailbox</a></p><p>To send Mail and other types of notification (Websockets/ActionCable channels, Slack, Microsoft Teams, Twilio (SMS), Vonage / Nexmo (SMS)) use <a href="https://github.com/excid3/noticed">noticed</a></p></div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-22' href='slides_rails_gems.html#/22'>◻</a></p>
<h3 id="http-requests"><a class="anchorlink" href="#http-requests"><span>2.15</span> HTTP Requests</a></h3><p>This might be handy for downloading from Webpages or APIs</p>
<ul>
<li>gem <a href="https://github.com/taf2/curb">curb</a> - the http library curl for ruby</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-23' href='slides_rails_gems.html#/23'>◻</a></p>
<h3 id="using-apis"><a class="anchorlink" href="#using-apis"><span>2.16</span> Using APIs</a></h3>
<ul>
<li>gem <a href="https://github.com/octokit/octokit.rb">octokit</a> - for github</li>
<li>gem <a href="https://github.com/sferik/twitter">twitter</a></li>
<li>gem <a href="https://github.com/arsduo/koala">koala</a> - for facebook</li>
<li>gem <a href="https://github.com/sinisterchipmunk/gravatar">gravatar</a></li>
<li>gem <a href="https://github.com/attack/barometer">barometer</a> - A multi API consuming weather forecasting superstar</li>
<li>gem <a href="https://github.com/apneadiving/Google-Maps-for-Rails">gmaps4rails</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-24' href='slides_rails_gems.html#/24'>◻</a></p>
<h3 id="geo-information-geocoding"><a class="anchorlink" href="#geo-information-geocoding"><span>2.17</span> Geo Information, Geocoding</a></h3><p>sometimes you want to convert longitude/latitude coordinates
to street addresses, or the reverse</p>
<ul>
<li>gem <a href="https://github.com/alexreisner/geocoder">geocoder</a></li>
</ul>
<p>Use postgres's inbuilt geographical features:</p>
<ul>
<li>gem <a href="http://www.rubygeocoder.com/">activerecord-postgis-adapter</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-25' href='slides_rails_gems.html#/25'>◻</a></p>
<h3 id="pdf-excel-csv"><a class="anchorlink" href="#pdf-excel-csv"><span>2.18</span> PDF, Excel, csv, ...</a></h3>
<ul>
<li>gem <a href="https://github.com/yob/pdf-reader">pdf-reader</a></li>
<li>gem <a href="https://github.com/mileszs/wicked_pdf/">wicket_pdf</a></li>
<li>gem <a href="https://github.com/zdavatz/spreadsheet">spreadsheet</a></li>
<li>gem <a href="https://github.com/tilo/smarter_csv">smarter_csv</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-26' href='slides_rails_gems.html#/26'>◻</a></p>
<h3 id="one-rails-code-for-many-sites-tenants"><a class="anchorlink" href="#one-rails-code-for-many-sites-tenants"><span>2.19</span> One Rails Code for Many Sites ("Tenants")</a></h3>
<ul>
<li>gem <a href="http://planetruby.github.io/gems/2020/08-acts-as-tenant.html">acts_as_tenant</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-27' href='slides_rails_gems.html#/27'>◻</a></p>
<h3 id="tracking-users"><a class="anchorlink" href="#tracking-users"><span>2.20</span> Tracking Users</a></h3>
<ul>
<li>gem <a href="https://github.com/ankane/ahoy">ahoy</a></li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-28' href='slides_rails_gems.html#/28'>◻</a></p>
<h3 id="testing"><a class="anchorlink" href="#testing"><span>2.21</span> Testing</a></h3>
<ul>
<li>gem <a href="https://github.com/thoughtbot/factory_bot_rails">factory_bot_rails</a> for creating test data.</li>
<li>gem <a href="https://github.com/jnicklas/capybara">capybara</a> as the "browser" for acceptance tests, with</li>
<li>gem <a href="https://github.com/thoughtbot/capybara-webkit">capybara-webkit</a> for testing client side javascript.</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-29' href='slides_rails_gems.html#/29'>◻</a></p>
<h3 id="understanding-your-code-better"><a class="anchorlink" href="#understanding-your-code-better"><span>2.22</span> Understanding your Code better</a></h3><p><img src="images/gem-better_errors.png" alt="better_errors screenshot"></p>
<ul>
<li>gem <a href="https://github.com/charliesome/better_errors">better_errors</a></li>
<li>gem <a href="https://github.com/dejan/rails_panel/tree/master/meta_request">meta_request</a> - supporting gem for <a href="https://github.com/dejan/rails_panel">Rails Panel, a Google Chrome extension for Rails development</a></li>
<li>gem <a href="https://github.com/ctran/annotate_models">annotate</a> - inserts the db schema as comments in your model.rb file</li>
<li>gem <a href="https://github.com/preston/railroady">railroady</a> - UML diagram generation for Rails projects, capable of analyzing existing models and controllers</li>
<li>gem <a href="https://github.com/flyerhzm/bullet">bullet</a> - helps you improve your usage of activerecord queries</li>
<li>gem <a href="https://github.com/presidentbeef/brakeman">brakeman</a> - checks for security vulnerabilities</li>
<li>gem <a href="https://github.com/railsbp/rails_best_practices">rails_best_practices</a></li>
<li>gem <a href="https://github.com/bbatsov/rubocop">rubocop</a> - static code analyzer</li>
<li>gem <a href="https://github.com/schneems/derailed_benchmarks">derailed_benchmarks</a></li>
<li>gem <a href="">metric_fu</a> - many code metrics for your rails project</li>
<li>gem <a href="https://github.com/MainShayne233/happy_gemfile#happygemfile">happy_gemfile</a> - keep your Gemfile sorted</li>
</ul>
</div>
<div class='slide'>
<p class='slide_break_block'><a class='slide_break' id='slide-30' href='slides_rails_gems.html#/30'>◻</a></p>
<h2 id="ressources"><a class="anchorlink" href="#ressources"><span>3</span> Ressources</a></h2>
<ul>
<li><a href="https://rubygems.org/">Ruby Gems</a></li>
<li><a href="https://bundler.io/">Bundler</a></li>
<li><a href="https://github.com/markets/awesome-ruby">awesome-ruby</a></li>
<li>the <a href="https://www.ruby-toolbox.com/">Ruby Toolbox</a> is organized in categories that help you find alternative solutions</li>
<li><a href="https://www.youtube.com/watch?v=4DqzaqeeMgY">How does Bundler work, anyway?</a> talk by Andre Arko at RubyConf 2015</li>
<li><a href="https://www.fastruby.io/blog/ruby/rails/versions/compatibility-table.html">Ruby and Rails compatability table</a></li>
</ul>
</div>
</div>
</div>
</main>
<hr class="hide" />
<footer id="page_footer">
<div class="wrapper">
<p class="copyright">published under <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/at/deed.de">creative commons by-nc-sa</a> in 2012-2025 by <a href="https://brigitte-jellinek.at">Brigitte Jellinek</a>.
</p>
<p>If you want to contribute: <a href="https://github.com/backend-development/backend-development-textbook/fork">fork the source on github</a>
</p>
<p>Favicon "backend development" by Arkinasi from <a href="https://thenounproject.com/browse/icons/term/backend-development/" target="_blank" title="backend development Icons">Noun Project</a> (CC BY 3.0)</p>
</div>
</footer>
</body>
</html>