-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdating-rails.html
More file actions
475 lines (473 loc) · 36.2 KB
/
updating-rails.html
File metadata and controls
475 lines (473 loc) · 36.2 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
<!DOCTYPE html>
<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Updating to Rails 5.0 · RailsApps</title>
<meta name="viewport" content="width=device-width">
<link href="https://plus.google.com/117374718581973393536" rel="publisher">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/css/normalize.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/css/foundation.min.css">
<link rel="stylesheet" href="http://railsapps.github.io/css/railsapps.css" />
<link rel="stylesheet" href="http://railsapps.github.io/css/syntax.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="http://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<script type="text/javascript">
window.analytics=window.analytics||[],window.analytics.methods=["identify","group","track","page","pageview","alias","ready","on","once","off","trackLink","trackForm","trackClick","trackSubmit"],window.analytics.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),window.analytics.push(a),window.analytics}};for(var i=0;i<window.analytics.methods.length;i++){var key=window.analytics.methods[i];window.analytics[key]=window.analytics.factory(key)}window.analytics.load=function(t){if(!document.getElementById("analytics-js")){var a=document.createElement("script");a.type="text/javascript",a.id="analytics-js",a.async=!0,a.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.io/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n)}},window.analytics.SNIPPET_VERSION="2.0.9",
window.analytics.load("l1stqfqqbf");
window.analytics.page();
window.analytics.ready(function () {
ga('require', 'linker');
ga('linker:autoLink', ['railscomposer.com','learn-rails.com','blog.railsapps.org','tutorials.railsapps.org']);
});
</script>
</head>
<body>
<div class="fixed">
<nav class="top-bar" data-topbar>
<ul class="title-area">
<li class="name">
<a href="http://railsapps.github.io/" class="brand">RailsApps Project</a>
</li>
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<section class="top-bar-section">
<ul class="right">
<li><a href="https://tutorials.railsapps.org/" class="google">Tutorials</a></li>
<li><a href="http://twitter.com/rails_apps" class="twitter">Twitter</a></li>
<li><a href="http://blog.railsapps.org/" class="twitter">Blog</a></li>
<li><a href="https://github.com/RailsApps" class="github">GitHub Repository</a></li>
</ul>
</section>
</nav>
</div>
<div class="row">
<div class="large-12 columns">
<div class="content wikistyle gollum textile">
<h1>Updating to Rails 5.0</h1>
<h4>by Daniel Kehoe</h4>
<p><em>Last updated 16 August 2016</em></p>
<p>Upgrading to Rails 5.0, the newest Ruby on Rails version. How to update Rails versions and upgrade Rails applications. Instructions and advice.</p>
<h4>How to Upgrade Rails</h4>
<p>This article shows how to add a new version of Rails while keeping an old version. Rails is revised frequently and you’ll likely need more than one version. Don’t simply replace an old version of Rails with another. Instead, set up your development environment with multiple versions of Rails so you can easily switch between them. This article shows how to switch between versions of Ruby and Rails using <a href="https://rvm.io/"><span class="caps">RVM</span></a>, the Ruby Version Manager.</p>
<h4>Updating Rails Applications</h4>
<p>Rails is actively maintained by a large community of developers, which means constant innovation, improvements, and attention to security. You must actively and regularly maintain your Rails applications. Upgrade your Rails applications whenever a new version of Rails is released. If you neglect to update regularly, upgrading several versions at once may require considerable effort, making it difficult to resolve security vulnerabilities quickly. If you don’t update Rails, you leave your application and its server open to attack. Here’s advice on timing:</p>
<ul>
<li>update security patch versions immediately</li>
<li>wait a month after a new major version is released to see if others report issues</li>
<li>upgrade before the next major version is released (within a year, typically)</li>
</ul>
<p>If you wait too long to upgrade, the community moves on and you’ll find it difficult get help with any issues.</p>
<h4>Don’t Just Update Rails</h4>
<p>It is important to set up your development environment with the most current version of all the gems that are needed for development. Developers often install the newest version of Rails but neglect other components needed for Rails to run successfully.</p>
<h4><a href="http://railsapps.github.io/"><img src="http://railsapps.github.io/images/join/join-railsapps.png" title="Join RailsApps" alt="Join RailsApps"></a></h4>
<h4>What is the RailsApps Project?</h4>
<p>This is an article from the RailsApps project. The <a href="http://railsapps.github.io/">RailsApps project</a> provides example applications that developers use as starter apps. Hundreds of developers use the apps, report problems as they arise, and propose solutions. Rails changes frequently; each application is known to work and serves as your personal “reference implementation.” Support for the project comes from developers who purchase the <a href="https://tutorials.railsapps.org/">Capstone Rails Tutorials</a>.</p>
<h4>Stay Informed</h4>
<p>These two weekly email newsletters will keep you informed about new Rails releases:</p>
<ul>
<li><a href="http://rubyweekly.com/">Ruby Weekly</a></li>
<li><a href="http://greenruby.org/">Green Ruby News</a></li>
</ul>
<p>Another weekly email newsletter is more technical, and focused on code arriving in the next version of Rails:</p>
<ul>
<li><a href="http://rails-weekly.goodbits.io/">This Week in Rails</a></li>
</ul>
<p>You also can follow <a href="http://twitter.com/rails_apps">@rails_apps</a> on Twitter for news.</p>
<h2>Ruby Versions</h2>
<p>You should use the newest version of Ruby with a new Rails application. Rails versions 3.2 to 4.2 were built to work with any version of Ruby from 1.9.3 to 2.2, allowing flexibility. However, Rails 5.0 requires Ruby 2.2.2 or newer. If you have an older application, take time to make sure it runs on the newest version of Ruby so you can upgrade to Rails 5.0.</p>
<p>To switch between Ruby versions, you’ll need a Ruby version manager such as <a href="https://rvm.io/"><span class="caps">RVM</span></a>, <a href="https://github.com/postmodern/chruby">chruby</a>, or Sam Stephenson’s <a href="https://github.com/sstephenson/rbenv">rbenv</a>.</p>
<h4>
<span class="caps">RVM</span>, chruby, or rbenv?</h4>
<p>Rails developers love to debate the merits of their tools and you’ll hear strong opinions about preferences for <span class="caps">RVM</span>, chruby, or rbenv. <a href="https://github.com/postmodern/chruby">Chruby</a> is the simplest; you’ll need a separate tool such as <a href="https://github.com/postmodern/ruby-install">ruby-install</a> to install Ruby versions. <a href="https://github.com/sstephenson/rbenv">Rbenv</a> is a favorite among people who are experienced Unix users. I recommend <a href="https://rvm.io/"><span class="caps">RVM</span></a> for beginners because it is robust and full-featured, with options for installing Ruby and managing sets of gems. This article will show how to use <span class="caps">RVM</span> to manage Rails versions, though you can adapt the principles for chruby or rbenv.</p>
<h4>Installing Ruby Versions</h4>
<p>These articles from the RailsApps project will show you how to install multiple versions of Ruby using <span class="caps">RVM</span>:</p>
<p><a href="http://railsapps.github.io/installrubyonrails-mac.html"><strong>Install Ruby on Rails – Mac OS X</strong></a></p>
<p><a href="http://railsapps.github.io/installrubyonrails-ubuntu.html"><strong>Install Ruby on Rails – Ubuntu</strong></a></p>
<p>If you’re using Windows, see the article <a href="http://railsapps.github.io/installing-rails.html">Installing Rails</a>.</p>
<p>If you are not using <span class="caps">RVM</span> already, see the articles to get started with multiple versions of Ruby. The articles are detailed and provide good advice, so it is worthwhile to take a look if you haven’t read the articles previously.</p>
<h2>Rails 5.0</h2>
<p>Rails 5.0 is the current stable version. It was released on June 30, 2016 after six months of beta releases.</p>
<p>Notable additions in Rails 5.0 include an option for an <span class="caps">API</span>-only application suitable for use as a backend to JavaScript or mobile applications. Also <a href="https://github.com/rails/rails/tree/master/actioncable">Action Cable</a> for live features such as chat and notifications.</p>
<p>Learn more about Rails 5.0:</p>
<ul>
<li><a href="http://guides.rubyonrails.org/5_0_release_notes.html">Rails 5.0 Release Notes</a></li>
<li><a href="http://weblog.rubyonrails.org/2015/12/18/Rails-5-0-beta1/">Rails 5.0.0.beta1: Action Cable, <span class="caps">API</span> mode, Rails command</a></li>
<li><a href="http://blog.michelada.io/whats-new-in-rails-5" title="Mario Alberto Chavez">What’s new in Rails 5?</a></li>
<li><a href="https://blog.engineyard.com/2015/a-look-at-rails-5" title="Engine Yard">A Look at Rails 5</a></li>
<li><a href="http://www.sitepoint.com/whats-new-rails-5/" title="SitePoint">What’s New in Rails 5</a></li>
</ul>
<p><em>What You Need to Know:</em> Rails 5.0 is the current stable version. Update to Rails 5.0 as soon as possible so you can keep your application current.</p>
<h2>Check the Gem Manager</h2>
<p><a href="https://rubygems.org/gems/rubygems-update">RubyGems</a> is the gem manager in Ruby.</p>
<p>Check the installed gem manager version. You may see:</p>
<pre>
$ gem -v
2.4.8
</pre>
<p>At the time this was written, a <a href="https://rubygems.org/gems/rubygems-update">newer RubyGems</a> version was available. Use <code>gem update --system</code> to upgrade the Ruby gem manager:</p>
<pre>
$ gem update --system
</pre>
<h2>
<span class="caps">RVM</span> Gemsets</h2>
<p><span class="caps">RVM</span> gives you <em>gemsets</em>, which are sandboxed environments that let you maintain separate sets of gems. Gemsets are ideal for multiple versions of Rails.</p>
<p>Display a list of gemsets:</p>
<pre>
$ rvm gemset list
gemsets for ruby-2.3.1
=> (default)
global
</pre>
<p>Only the “default” and “global” gemsets are pre-installed.</p>
<p>If you get an error “rvm is not a function,” close your console and open it again.</p>
<h2 id="gems">RVM’s Global Gemset</h2>
<p>See what gems are installed in the “global” gemset:</p>
<pre>
$ rvm gemset use global
$ gem list
</pre>
<p>A trouble-free development environment requires the newest versions of the default gems.</p>
<p>Several gems are installed with Ruby or the <span class="caps">RVM</span> default gemset:</p>
<ul>
<li><a href="https://rubygems.org/gems/bundler">bundler</a></li>
<li><a href="http://rubygems.org/gems/bundler-unload">bundler-unload</a></li>
<li><a href="http://rubygems.org/gems/rake">rake</a></li>
<li><a href="http://rubygems.org/gems/rubygems-bundler">rubygems-bundler</a></li>
<li><a href="http://rubygems.org/gems/rvm">rvm</a></li>
</ul>
<p>To get a list of gems that are outdated:</p>
<pre>
$ gem outdated
### list not shown for brevity
</pre>
<p>To update all stale gems:</p>
<pre>
$ gem update
### list not shown for brevity
</pre>
<p>You can track updates to gems at the RubyGems.org site by creating an account and visiting your <a href="https://rubygems.org/dashboard">dashboard</a>. Search for each gem you use and “subscribe” to see a feed of updates in the dashboard (an <span class="caps">RSS</span> feed is available from the dashboard). As an alternative, use the <a href="https://gemnasium.com/">Gemnasium</a> service which surveys your GitHub repo and sends email notifications when gem versions change. Gemnasium is free for public repositories with a premium plan for private repositories.</p>
<h4>Nokogiri</h4>
<p><a href="http://nokogiri.org/">Nokogiri</a> is a gem that is a dependency for many other gems (specifically, the <a href="https://github.com/rails/rails-html-sanitizer">rails-html-sanitizer</a> gem and its dependency, the <a href="https://github.com/flavorjones/loofah">loofah</a> gem). Nokogiri is a gem that requires compilation for your specific operating system. As such, if your system environment doesn’t match Nokogiri’s requirements, compilation of Nokogiri will fail. If your system is configured properly, you’ll be able to compile Nokogiri. However, compilation takes time. Every time you install the Nokogiri gem, you’ll wait (as long as five minutes).</p>
<p>To save time, install the Nokogiri gem in the <span class="caps">RVM</span> global gemset:</p>
<pre>
$ gem install nokogiri
</pre>
<p>During installation, Nokogiri will display two lengthy messages in the console. It will also pause without displaying any progress for as long as five minutes. Don’t assume installation has failed unless you see an error message or you’ve waited more than ten minutes.</p>
<p>If installation fails, make sure your system is configured properly (look for help on <a href="http://stackoverflow.com/questions/tagged/nokogiri">Stack Overflow</a>).</p>
<h2>Simple Rails Update</h2>
<p>Here’s the simplest way to update an application to a new version of Rails. Use this method for updates between patch versions, for example from Rails 4.2.4 to 4.2.5. Use this simple procedure if you don’t think you’ll need to move back and forth between versions. Make sure you have committed the Gemfile and Gemfile.lock files to git so you can restore a known working version of your application if necessary. I recommend using <span class="caps">RVM</span>, the <a href="https://rvm.io/">Ruby Version Manager</a> when you need to switch between Rails versions (described in the next section).</p>
<p>Your Gemfile specifies the Rails version used by your application. If you have a Rails 4.2.4 application:</p>
<pre>
source 'https://rubygems.org'
gem 'rails', '4.2.4'
</pre>
<p>You can change the Rails version to a newer version of Rails. For example, update it to Rails 4.2.5:</p>
<pre>
source 'https://rubygems.org'
gem 'rails', '4.2.5'
</pre>
<p>Then run:</p>
<pre>
$ bundle update rails
</pre>
<p>The Rails gem will be updated by bundler and the Gemfile.lock file will be updated to record the new gem version.</p>
<p>You’ll see a message showing which version of Rails is running when you start the web server.</p>
<p>This approach is appropriate if you are moving between patch versions. If you’re making a big upgrade, for example from Rails 4.2 to Rails 5.0, use <span class="caps">RVM</span> and follow the procedure below.</p>
<h2>Rails Installation With <span class="caps">RVM</span> Gemsets</h2>
<p>You can install Rails directly into the global gemset. However, many developers prefer to keep the global gemset sparse and install Rails into project-specific gemsets, so each project has the appropriate version of Rails. You may also wish to have gemsets for different versions of Rails, for example Rails 4.2 and Rails 5.0.</p>
<h4>Rails 4.2</h4>
<p>First, make a gemset just for the 4.2 release:</p>
<pre>
$ rvm use ruby-2.3.1@rails4.2 --create
</pre>
<p>If you want the Rails 4.2.5 release:</p>
<pre>
$ gem install rails --version=4.2.5
$ rails -v
</pre>
<h4>Rails 5.0</h4>
<p>Make another gemset for the Rails 5.0 version:</p>
<pre>
$ rvm use ruby-2.3.1@rails5.0 --create
$ gem install rails
$ rails -v
</pre>
<h4>Other Rails Versions</h4>
<p>You can install a specific version if you need it.</p>
<p>For example, if you want the Rails 3.2.18 release:</p>
<pre>
$ rvm use ruby-2.3.1@rails3.2 --create
$ gem install rails --version=3.2.18
$ rails -v
</pre>
<h4>Switching Between Gemsets</h4>
<p>You can easily switch between gemsets.</p>
<p>For example, to use Rails 4.2:</p>
<pre>
$ rvm use ruby-2.3.1@rails4.2
</pre>
<p>To use Rails 5.0:</p>
<pre>
$ rvm use ruby-2.3.1@rails5.0
</pre>
<h2>Specifying Gemsets</h2>
<p>If you’ve already created an application, you can create a project-specific gemset. Here’s how to create a gemset for an application named “myapp” and create <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files in the application’s project directory:</p>
<pre>
$ rvm use ruby-2.3.1@myapp --ruby-version --create
</pre>
<p>The next time you <code>cd</code> into the project directory, <span class="caps">RVM</span> will read the <strong>.ruby-version</strong> and <strong>.ruby-gemset</strong> files and automatically configure your development environment to use the correct Ruby version and gemset. If it is a new gemset, and a Gemfile is present in the project directory, you can use <code>bundle install</code> to install the necessary gems.</p>
<h2>Examine Version Differences</h2>
<p>Before you update Rails, take time to find out how the default new Rails application has changed.</p>
<p>There are two ways to compare differences in a simple Rails application:</p>
<ul>
<li>visit the site <a href="http://railsdiff.org/">railsdiff.org</a>
</li>
<li>create new Rails starter applications in Rails 4.2 and Rails 5.0 and examine the differences</li>
</ul>
<p>The best way to see differences between versions of the Rails default application is by visiting the <a href="http://railsdiff.org/">railsdiff.org</a> site.</p>
<p>If you want to see the differences and copy and paste code, you can create two versions of a starter application. First, create a starter app with the old version of Rails. Then switch gemsets and create a starter app with the new version of Rails.</p>
<p>Let’s assume you want to compare Rails 4.2 and Rails 5.0.</p>
<pre>
$ rvm use ruby-2.3.1@rails4.2
$ rails new myapp4.2
$ rvm use ruby-2.3.1@rails5.0
$ rails new myapp5.0
</pre>
<p>Compare the two applications with a file compare tool.</p>
<p>Major Rails updates often make many changes. Patch updates seldom change the default new Rails application.</p>
<h2>Updating a Rails Application</h2>
<p>First, review the official release notes:</p>
<ul>
<li><a href="http://guides.rubyonrails.org/5_0_release_notes.html">Ruby on Rails 5.0 Release Notes</a></li>
</ul>
<p>The release notes are very detailed. In many cases, none of the changes will affect your application. Scan the release notes to identify any issues that may affect you. You’ll have to know your application well enough that you recognize changes that may affect your code.</p>
<p>Then try running your application with the newer version of Rails.</p>
<h4>Using <span class="caps">RVM</span>
</h4>
<p>With <span class="caps">RVM</span>, it’s convenient to preserve the set of gems that are known to work with your application. If you have difficulties with new gem versions, you can switch back to the older gemset easily, without reinstalling your old gems.</p>
<p>Let’s assume you have an application named “myapp” that runs with Rails 4.2.5.</p>
<p>We’ll upgrade it to Rails 5.0.</p>
<p>Start the upgrade in the application’s root directory:</p>
<pre>
$ cd myapp
</pre>
<h4>Rails 4.2</h4>
<p>If you already have a project-specific gemset, rename it:</p>
<pre>
$ rvm gemset rename myapp Rails4.2_myapp
</pre>
<p>If not, create a project-specific gemset using Ruby Ruby 2.3.1 and Rails 4.2:</p>
<pre>
$ rvm use ruby-2.3.1@rails4.2_myapp --create
$ rvm gemset list
$ bundle install
</pre>
<p>Test the application. It should be working as before.</p>
<h4>Git Workflow</h4>
<p>If you are comfortable using git branches, this is a good time to create one.</p>
<pre>
$ git checkout -b upgrading
</pre>
<p>The command creates a new branch named “upgrading” and switches to it, analogous to copying all your files to a new directory and moving to work in the new directory (though that is not really what happens with git).</p>
<h4>Rails 5.0</h4>
<p>Create a new project-specific gemset for Rails 5.0:</p>
<pre>
$ rvm use ruby-2.3.1@Rails5.0_myapp --create
$ rvm gemset list
</pre>
<p>Check that the only installed gems are those from the global gemset:</p>
<pre>
$ gem list
*** LOCAL GEMS ***
bundler (...)
rake (...)
rubygems-bundler (...)
rvm (...)
</pre>
<p>Check a list of <a href="http://rubygems.org/gems/rails">versions of Rails</a> to find the newest version of Rails.</p>
<p>Your Gemfile specifies the Rails version used by your application:</p>
<pre>
source 'https://rubygems.org'
gem 'rails', '4.2.5'
.
.
.
</pre>
<p>Change the Rails version to 5.0.0 (or a newer one if available):</p>
<pre>
source 'https://rubygems.org'
gem 'rails', '5.0.0'
.
.
.
</pre>
<p>Then update the gems specified in the Gemfile:</p>
<pre>
$ bundle update
</pre>
<p>Each gem specified in the Gemfile will be installed by bundler and the Gemfile.lock file will be updated to record the gem versions. You can run <code>gem list</code> again to see the gems that were installed in the gemset.</p>
<p>Check the Rails version:</p>
<pre>
$ rails -v
</pre>
<p>Test the application and make any changes needed to run it with Rails 5.0.</p>
<h4>Updating Configuration Files</h4>
<p>Minor Rails version updates seldom require changes to configuration files. Major Rails updates often change configuration files. If you don’t make the required configuration file changes, you’ll likely see deprecation warnings when you launch a Rails application.</p>
<p>Rails provides a <code>rails rails:update</code> task to update configuration files. Be sure you’ve committed your application with git before running <code>rails rails:update</code> in case you need to roll back changes.</p>
<pre>
$ git add .
$ git commit -m 'before rails rails update'
$ rails rails:update
</pre>
<p>The <code>rails rails:update</code> will identify every configuration file in your application that differs from a new Rails application. When it detects a conflict, it will offer to overwrite your file.</p>
<p>Don’t blindly allow <code>rails rails:update</code> to overwrite your files. Many of your files will be different because you’ve made changes from a default new Rails application. You’ll need to check each file to determine if <code>rails rails:update</code> is seeing your own changes or pointing out changes due to a Rails update.</p>
<p>When <code>rails rails:update</code> offers to overwrite a file, enter <code>d</code> (for “diff”) and review the differences. Most differences will be your own. If you’re uncertain, don’t overwrite the file; make a note for yourself and investigate later. If you are certain that the difference is due to a Rails version change, you can allow <code>rails rails:update</code> to overwrite the file.</p>
<h4>New Default Initializers</h4>
<p>As of Rails 5.0, a configuration file shows all changed configuration settings in a single initializer file. Take a look at the file:</p>
<ul>
<li><em>config/initializers/new_framework_defaults.rb</em></li>
</ul>
<p>Examine this file and see if your application relies on any configuration settings that have changed from defaults in the new Rails version. Most simple applications will not be affected by the changed defaults.</p>
<h4>Git Workflow</h4>
<p>If your application is running successfully under Rails 5.0, commit any changes.</p>
<pre>
$ git add -A
$ git commit -m "work in progress"
$ git checkout master
$ git merge --squash upgrading
$ git commit -m "upgrade to Rails 5.0"
</pre>
<p>The commands commit the changes to the working branch named “upgrading,” switch to the master branch, and then merge the changes into the master branch for a final commit.</p>
<h2 id="updating">Updating Your Application</h2>
<p>After updating Rails and configuration files, run your test suite (hopefully, you have tests; this is why you need them!).</p>
<p>Often, when the changes to Rails are minor, you will not need to update your application. When a major new version of Rails is released, you will have to rework parts of your application. Here are resources you can use to identify specific code that needs to be updated. Take a look at a checklist from Jesse Wolgamott:</p>
<ul>
<li><a href="http://www.rails-upgrade-checklist.com/">Rails Upgrade Checklist</a></li>
</ul>
<h4 id="torails4">Rails 3.2 to Rails 4.0</h4>
<ul>
<li>Ebook: Andy Lindeman <a href="http://www.upgradingtorails4.com/">Upgrading to Rails 4</a>
</li>
<li>Ebook: Philip De Smedt <a href="http://upgradetorails4.com/">Upgrade to Rails 4</a>
</li>
<li>Blog post: Maciej Mensfeld <a href="http://dev.mensfeld.pl/2013/06/upgrading-to-rails-4-0-from-rails-3-2-test-case-part-i-preparations-configuration-gems/">Upgrading to Rails 4.0 from Rails 3.2</a>
</li>
<li>Blog post: Mario Chavez <a href="http://blog.crowdint.com/2013/03/07/upgrading-a-rails-application-to-4-0.html">Upgrading a Rails application to 4.0</a>
</li>
<li>Script: Michael de Silva <a href="https://github.com/bsodmike/upgrade_rails_3.2.12_to_4.0.0.beta1">upgrade_rails_3.2.12_to_4.0.0.beta1</a>
</li>
<li>Video: Code School <a href="http://rails4.codeschool.com/videos">Rails 4: Zombie Outlaws</a>
</li>
<li>Article: RailsGuides <a href="http://edgeguides.rubyonrails.org/upgrading_ruby_on_rails.html#upgrading-from-rails-3-2-to-rails-4-0">Upgrading from Rails 3.2 to Rails 4.0</a> (work-in-progress document)</li>
</ul>
<h4>Rails 3.1 to Rails 3.2</h4>
<ul>
<li>Railscast by Ryan Bates <a href="http://railscasts.com/episodes/318-upgrading-to-rails-3-2">Upgrading to Rails 3.2</a>
</li>
</ul>
<h2>Updating Other Gems</h2>
<p>It’s important to update the Rails gem when there are security fixes. You’ll seldom need to update other gems once you’ve deployed your application but you may want to stay informed of changes. You can track updates to gems by creating an account and visiting your <a href="https://rubygems.org/dashboard">dashboard</a> at the RubyGems.org site. Search for each gem you use and “subscribe” to see a feed of updates in the dashboard (an <span class="caps">RSS</span> feed is available from the dashboard). As an alternative, use the <a href="https://gemnasium.com/">Gemnasium</a> or <a href="https://www.versioneye.com/">VersionEye</a> services which survey your GitHub repo and send email notifications when gem versions change. The services are free for public repositories with a premium plan for private repositories.</p>
<p>You can update any gem by running <code>bundle update gem_name</code>. This installs the newest version of the gem (if the Gemfile entry doesn’t require a specific version) and updates the Gemfile.lock file.</p>
<p>You can run <code>bundle update</code> to update all gems at once. Bundler will observe the version rules specified in the Gemfile; when a specific version is specified in the Gemfile, running <code>bundle update</code> without changing the Gemfile entry won’t update a gem. Running <code>bundle update</code> installs new gem versions and updates the Gemfile.lock file. As an alternative to running <code>bundle update</code>, you can delete the Gemfile.lock file and run <code>bundle install</code> to replace the Gemfile.lock file.</p>
<p>If you are using <span class="caps">RVM</span> and multiple gemsets, it is best not to run <code>bundle update rails</code>. Instead, create a new gemset for the new Rails version as described above so you can switch gemsets as needed.</p>
<h2>Security</h2>
<p>By design, Rails encourages practices that avoid common web application vulnerabilities. The Rails security team actively investigates and patches vulnerabilities. If you use the most current version of Rails, you will be protected from known vulnerabilities. See the <a href="http://guides.rubyonrails.org/security.html">Ruby On Rails Security Guide</a> for an overview of potential issues and watch the <a href="https://groups.google.com/forum/?fromgroups#!forum/rubyonrails-security">Ruby on Rails Security Mailing List</a> for announcements and discussion.</p>
<h3>Your Application’s Secret Token</h3>
<p>Rails uses a session store to provide persistence between page requests. The default session store uses cookies. To prevent decoding of cookie data and hijacking a session, Rails encrypts cookie data using a secret key. When you create a new Rails application using the <code>rails new</code> command, a unique secret key is generated and written to the <strong>config/initializers/secret_token.rb</strong> file. If you’ve generated a Rails application and committed it only to a private GitHub repository, you do not need to change the secret key. However, if you’ve cloned a public GitHub repository or made your application publicly available on GitHub, you must change the secret key when you deploy. The command <code>rake secret</code> generates a new random secret you can use. The command won’t install the key; you have to copy the key from the console output to the <strong>config/initializers/secret_token.rb</strong> file. Remember, you should never deploy an application to production that uses a publicly available secret token (obviously, it is not secret if it is public!).</p>
<h2>Where to Get Help</h2>
<p>Your best source for help with problems is <a href="http://stackoverflow.com/questions/tagged/ruby-on-rails">Stack Overflow</a>. Your issue may have been encountered and addressed by others.</p>
</div>
<div class="comments" id="comments">
<div class="content wikistyle gollum">
<h2>Comments</h2>
</div>
<p>Is this helpful? Your encouragement fuels the project. Please tweet or add a comment. Couldn't get something to work? For the example apps and tutorials, it's best to open an issue on GitHub so we can help you.</p>
<div id="disqus_thread"></div>
<script type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
var disqus_shortname = 'railsapps'; // required: replace example with your forum shortname
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div><!-- class="comments" -->
</div><!-- class="columns" -->
</div><!-- class="row" -->
<footer class="row">
<div class="large-12 columns">
<div class="row">
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Getting Started</dt>
<dd><a href="http://railsapps.github.io/ruby-and-rails.html">Ruby on Rails</a></dd>
<dd><a href="http://railsapps.github.io/what-is-ruby-rails.html">What is Ruby on Rails?</a></dd>
<dd><a href="http://learn-rails.com/learn-ruby-on-rails.html">Learn Ruby on Rails</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-tutorial">Rails Tutorial</a></dd>
<dd><a href="http://learn-rails.com/ruby-on-rails-tutorial-for-beginners">Ruby on Rails Tutorial for Beginners</a></dd>
<dd><a href="http://railsapps.github.io/installing-rails.html">Install Ruby on Rails</a></dd>
<dd><a href="http://railsapps.github.io/installrubyonrails-mac.html">Install Ruby on Rails - Mac OS X</a></dd>
<dd><a href="http://railsapps.github.io/installrubyonrails-ubuntu.html">Install Ruby on Rails - Ubuntu</a></dd>
<dd><a href="http://railsapps.github.io/rubyonrails-nitrous-io.html">Ruby on Rails - Nitrous.io</a></dd>
<dd><a href="http://railsapps.github.io/updating-rails.html">Update Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-composer/">Rails Composer</a></dd>
<dd><a href="http://railsapps.github.io/">Rails Examples</a></dd>
<dd><a href="http://railsapps.github.io/rails-examples-tutorials.html">Rails Starter Apps</a></dd>
</dl>
</div>
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Articles</dt>
<dd><a href="http://railsapps.github.io/rails-authorization.html">Rails Authorization</a></dd>
<dd><a href="http://railsapps.github.io/rails-google-analytics.html">Analytics for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-heroku-tutorial.html">Heroku and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-javascript-include-external.html">JavaScript and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-environment-variables.html">Rails Environment Variables</a></dd>
<dd><a href="http://railsapps.github.io/rails-git.html">Git and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-github.html">Rails GitHub</a></dd>
<dd><a href="http://railsapps.github.io/rails-send-email.html">Send Email with Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-haml.html">Haml and Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-default-application-layout.html">Rails Application Layout</a></dd>
<dd><a href="http://railsapps.github.io/rails-html5-boilerplate.html">HTML5 Boilerplate for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-3-2-example-gemfile.html">Example Gemfiles for Rails</a></dd>
<dd><a href="http://railsapps.github.io/rails-application-templates.html">Rails Application Templates</a></dd>
<dd><a href="http://railsapps.github.io/rails-product-planning.html">Rails Product Planning</a></dd>
<dd><a href="http://railsapps.github.io/rails-project-management.html">Rails Project Management</a></dd>
</dl>
</div>
<div class="medium-4 large-4 columns">
<dl class="footer_nav">
<dt>RailsApps · Tutorials</dt>
<dd><a href="http://railsapps.github.io/twitter-bootstrap-rails.html">Rails Bootstrap</a></dd>
<dd><a href="http://railsapps.github.io/rails-foundation.html">Rails Foundation</a></dd>
<dd><a href="http://railsapps.github.io/rails-omniauth/">OmniAuth Tutorial</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-devise.html">Rails Devise Tutorial</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-devise-rspec-cucumber.html">Devise RSpec</a></dd>
<dd><a href="http://railsapps.github.io/tutorial-rails-bootstrap-devise-cancan.html">Devise Bootstrap</a></dd>
<dd><a href="http://railsapps.github.io/rails-devise-roles">Role-Based Authorization</a></dd>
<dd><a href="http://railsapps.github.io/rails-devise-pundit">Rails Authorization with Pundit</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-stripe-membership-saas">Rails Membership Site with Stripe</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-recurly-subscription-saas">Rails Subscription Site with Recurly</a></dd>
<dd><a href="https://tutorials.railsapps.org/rails-prelaunch-signup">Startup Prelaunch Signup Application</a></dd>
</dl>
<dl class="footer_nav">
<dt>RailsApps Profile</dt>
<dd><a href="https://plus.google.com/108039160165742774777?rel=author">Google</a></dd>
<dd><a href="https://plus.google.com/117374718581973393536" rel="publisher">Find us on Google+</a></dd>
</dl>
</div>
</div>
</div>
</footer>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/foundation/5.2.2/js/foundation.min.js"></script>
<script>
$(document).foundation();
</script>
</body>
</html>