# When should Discourse upgrade to Rails 5?

**URL:** https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123
**Category:** Development
**Created:** [30 ביולי,‏ 2017,‏ 9:26pm UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123 "2017-07-30T21:26:52Z")
**Posts on this page:** 11
**Page:** 3

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [27 בספטמבר,‏ 2017,‏ 7:39pm UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/42 "2017-09-27T19:39:07Z")

</div>

@tgxworld I think the rails 5 upgrade may have introduced an issue with error handling in the application controller.

I think I’ve tracked it down to any call to `rescue_discourse_actions` which has `include_ember: true`. I use this in my category-lockdown plugin (hence why I noticed), but it is also used in core.

One example of this is the recovery from an InvalidAccess exception:

> <https://github.com/discourse/discourse/blob/main/app/controllers/application_controller.rb#L143-L150>

If you try and access a topic you do not have access to, the server throws a 500 error. This is the stack trace I get when reproducing on my dev instance:

> **Stack Trace**
>
> ```plaintext
> ActionView::MissingTemplate - Missing template topics/show, application/show with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:
> * "/Users/David/Web-Projects/discourse/app/views"
> * "/Users/David/Web-Projects/discourse/plugins/docker_manager/app/views"
> * "/Users/David/.rvm/gems/ruby-2.3.4/gems/discourse-qunit-rails-0.0.11/app/views"
> :
> actionview (5.1.3) lib/action_view/path_set.rb:46:in `find'
> actionview (5.1.3) lib/action_view/lookup_context.rb:116:in `find'
> actionview (5.1.3) lib/action_view/renderer/abstract_renderer.rb:18:in `find_template'
> actionview (5.1.3) lib/action_view/renderer/template_renderer.rb:38:in `determine_template'
> actionview (5.1.3) lib/action_view/renderer/template_renderer.rb:8:in `render'
> actionview (5.1.3) lib/action_view/renderer/renderer.rb:42:in `render_template'
> actionview (5.1.3) lib/action_view/renderer/renderer.rb:23:in `render'
> actionview (5.1.3) lib/action_view/rendering.rb:103:in `_render_template'
> actionpack (5.1.3) lib/action_controller/metal/streaming.rb:217:in `_render_template'
> actionview (5.1.3) lib/action_view/rendering.rb:83:in `render_to_body'
> actionpack (5.1.3) lib/action_controller/metal/rendering.rb:52:in `render_to_body'
> actionpack (5.1.3) lib/action_controller/metal/renderers.rb:141:in `render_to_body'
> actionpack (5.1.3) lib/abstract_controller/rendering.rb:24:in `render'
> actionpack (5.1.3) lib/action_controller/metal/rendering.rb:36:in `render'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
> activesupport (5.1.3) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
> /Users/David/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
> activesupport (5.1.3) lib/active_support/core_ext/benchmark.rb:12:in `ms'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
> activerecord (5.1.3) lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:43:in `render'
> app/controllers/application_controller.rb:165:in `rescue_discourse_actions'
> app/controllers/application_controller.rb:144:in `block in <class:ApplicationController>'
> activesupport (5.1.3) lib/active_support/rescuable.rb:115:in `block in handler_for_rescue'
> activesupport (5.1.3) lib/active_support/rescuable.rb:91:in `rescue_with_handler'
> activesupport (5.1.3) lib/active_support/rescuable.rb:164:in `rescue_with_handler'
> actionpack (5.1.3) lib/action_controller/metal/rescue.rb:23:in `rescue in process_action'
> actionpack (5.1.3) lib/action_controller/metal/rescue.rb:20:in `process_action'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
> activesupport (5.1.3) lib/active_support/notifications.rb:166:in `block in instrument'
> activesupport (5.1.3) lib/active_support/notifications/instrumenter.rb:21:in `instrument'
> activesupport (5.1.3) lib/active_support/notifications.rb:166:in `instrument'
> actionpack (5.1.3) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
> actionpack (5.1.3) lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
> activerecord (5.1.3) lib/active_record/railties/controller_runtime.rb:22:in `process_action'
> actionpack (5.1.3) lib/abstract_controller/base.rb:124:in `process'
> actionview (5.1.3) lib/action_view/rendering.rb:30:in `process'
> rack-mini-profiler (0.10.5) lib/mini_profiler/profiling_methods.rb:102:in `block in profile_method'
> actionpack (5.1.3) lib/action_controller/metal.rb:189:in `dispatch'
> actionpack (5.1.3) lib/action_controller/metal.rb:253:in `dispatch'
> actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
> actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:31:in `serve'
> actionpack (5.1.3) lib/action_dispatch/journey/router.rb:46:in `block in serve'
> actionpack (5.1.3) lib/action_dispatch/journey/router.rb:33:in `serve'
> actionpack (5.1.3) lib/action_dispatch/routing/route_set.rb:834:in `call'
> rack-protection (2.0.0) lib/rack/protection/frame_options.rb:31:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/strategy.rb:189:in `call!'
> omniauth (1.6.1) lib/omniauth/strategy.rb:167:in `call'
> omniauth (1.6.1) lib/omniauth/builder.rb:63:in `call'
> rack (2.0.3) lib/rack/conditional_get.rb:25:in `call'
> rack (2.0.3) lib/rack/head.rb:12:in `call'
> rack (2.0.3) lib/rack/session/abstract/id.rb:232:in `context'
> rack (2.0.3) lib/rack/session/abstract/id.rb:226:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/cookies.rb:613:in `call'
> activerecord (5.1.3) lib/active_record/migration.rb:556:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
> activesupport (5.1.3) lib/active_support/callbacks.rb:97:in `run_callbacks'
> actionpack (5.1.3) lib/action_dispatch/middleware/callbacks.rb:24:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/executor.rb:12:in `call'
> better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
> better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
> better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
> logster (1.2.7) lib/logster/middleware/reporter.rb:31:in `call'
> railties (5.1.3) lib/rails/rack/logger.rb:36:in `call_app'
> railties (5.1.3) lib/rails/rack/logger.rb:26:in `call'
> config/initializers/100-quiet_logger.rb:16:in `call'
> config/initializers/100-silence_logger.rb:29:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/request_id.rb:25:in `call'
> rack (2.0.3) lib/rack/method_override.rb:22:in `call'
> rack (2.0.3) lib/rack/runtime.rb:22:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/executor.rb:12:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/static.rb:125:in `call'
> actionpack (5.1.3) lib/action_dispatch/middleware/static.rb:125:in `call'
> rack (2.0.3) lib/rack/sendfile.rb:111:in `call'
> lib/middleware/missing_avatars.rb:21:in `call'
> lib/middleware/turbo_dev.rb:34:in `call'
> rack-mini-profiler (0.10.5) lib/mini_profiler/profiler.rb:282:in `call'
> message_bus (2.0.5) lib/message_bus/rack/middleware.rb:63:in `call'
> railties (5.1.3) lib/rails/engine.rb:522:in `call'
> railties (5.1.3) lib/rails/railtie.rb:185:in `method_missing'
> rack (2.0.3) lib/rack/urlmap.rb:68:in `block in call'
> rack (2.0.3) lib/rack/urlmap.rb:53:in `call'
> puma (3.9.1) lib/puma/configuration.rb:224:in `call'
> puma (3.9.1) lib/puma/server.rb:602:in `handle_request'
> puma (3.9.1) lib/puma/server.rb:435:in `process_client'
> puma (3.9.1) lib/puma/server.rb:299:in `block in run'
> puma (3.9.1) lib/puma/thread_pool.rb:120:in `block in spawn_thread'
> 
> ```

For a live example, try accessing a topic you do not have access to on meta (e.g. [this one](https://meta.discourse.org/t/progress-updates-for-discourse-chat-integration/65401/26) in incognito mode). Browser console shows a 500 error, and I would assume you have a sea of errors in the server logs.

Edit: it also looks like the handling of topic redirects is broken. For example, a link to

```plaintext
https://meta.discourse.org/t/automatic-second-post-wiki/70791/7

```

[works fine](https://meta.discourse.org/t/automatic-second-post-wiki/70791/7)

but if I omit the title:

```plaintext
https://meta.discourse.org/t/70791/7

```

[bad things happen](https://meta.discourse.org/t/70791/7)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [28 בספטמבר,‏ 2017,‏ 3:07am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/43 "2017-09-28T03:07:37Z")

</div>

> [@david](#):
>
> If you try and access a topic you do not have access to, the server throws a 500 error. This is the stack trace I get when reproducing on my dev instance:

Thanks @david, fixed in

[https://github.com/discourse/discourse/commit/4319d8a142ea23bdfc9025d137662aa17ac37bd0](https://github.com/discourse/discourse/commit/4319d8a142ea23bdfc9025d137662aa17ac37bd0)

> [@david](#):
>
> Edit: it also looks like the handling of topic redirects is broken. For example, a link to
> 
> [Automatic Second-Post Wiki? - #7 by DiscourseDude](https://meta.discourse.org/t/automatic-second-post-wiki/70791/7)
> 
> works fine
> 
> but if I omit the title:
> 
> [Automatic Second-Post Wiki? - #7 by DiscourseDude](https://meta.discourse.org/t/70791/7)
> 
> bad things happen

Hmm can you still reproduce this? It isn’t broken for me anymore.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [28 בספטמבר,‏ 2017,‏ 7:17am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/44 "2017-09-28T07:17:09Z")

</div>

2 posts were split to a new topic: [Guessing the keyboard height on iOS](https://meta.discourse.org/t/guessing-the-keyboard-height-on-ios/70919)

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [28 בספטמבר,‏ 2017,‏ 8:04am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/45 "2017-09-28T08:04:44Z")

</div>

> [@tgxworld](#):
>
> fixed

Great 😃

> [@tgxworld](#):
>
> Hmm can you still reproduce this?

Yes I can. It only errors when I click the link in the topic - if I open in a new tab then it works fine. So I guess something going wrong with the routing logic on the ember side.

If it’s not happening to anyone else then I’ll see if I can isolate what’s causing it for me.

---

<div class="post-metadata">

### Author: ![cpradio](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cpradio/32/4970_2.png) [@cpradio](https://meta.discourse.org/u/cpradio)
#### Post date: [28 בספטמבר,‏ 2017,‏ 10:17am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/46 "2017-09-28T10:17:25Z")

</div>

> [@david](#):
>
> If it’s not happening to anyone else then I’ll see if I can isolate what’s causing it for me.

It doesn’t seem to be just you, as your post showcasing it causes it here on Meta (at least for me). Normal click - Page not found error, Right Click open new window/tab - loads fine.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [28 בספטמבר,‏ 2017,‏ 5:44pm UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/47 "2017-09-28T17:44:52Z")

</div>

@tgxworld can you repro the above?

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [29 בספטמבר,‏ 2017,‏ 4:05am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/48 "2017-09-29T04:05:33Z")

</div>

Seems like the following links do not work as well. This isn’t a Rails 5 bug but rather a mismatch between how the topic routes are handled by Ember.

[https://meta.discourse.org/t/70791/7](https://meta.discourse.org/t/70791/7)  
[https://meta.discourse.org/t/70791](https://meta.discourse.org/t/70791)

---

<div class="post-metadata">

### Author: ![tgxworld](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tgxworld/32/106117_2.png) [@tgxworld](https://meta.discourse.org/u/tgxworld)
#### Post date: [29 בספטמבר,‏ 2017,‏ 6:07am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/49 "2017-09-29T06:07:07Z")

</div>

PR submitted in

[https://github.com/discourse/discourse/pull/5212](https://github.com/discourse/discourse/pull/5212)

@eviltrout Can you review this for me? Thank you!

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [29 בספטמבר,‏ 2017,‏ 2:35pm UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/50 "2017-09-29T14:35:00Z")

</div>

Sure, looks good to me. Merged.

---

<div class="post-metadata">

### Author: ![saiqulhaq](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/saiqulhaq/32/119871_2.png) [@saiqulhaq](https://meta.discourse.org/u/saiqulhaq)
#### Post date: [30 בספטמבר,‏ 2017,‏ 12:23pm UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/51 "2017-09-30T12:23:25Z")

</div>

`discourse_admin_statistics_digest` plugin doesn’t use `before_filter` method  
it’s not tied to controller

so it should be OK

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [15 באוקטובר,‏ 2017,‏ 1:29am UTC](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123/52 "2017-10-15T01:29:26Z")

</div>



[Previous page](https://meta.discourse.org/t/when-should-discourse-upgrade-to-rails-5/67123.md?page=2)
