What to use instead of `render :text` (and `render nothing: true`) in rails 5.1 and later?

The non-deprecated way is to use render :plain Rails Guide on Layouts and Rendering: 2.2.6 Rendering Text You can send plain text – with no markup at all – back to the browser by using the :plain option to render: render plain: “OK” Bonus Instead of render nothing: true (also removed), one should now use … Read more

What are the brackets [5.1] after ActiveRecord Migration and how does it work? [duplicate]

This is the new migration versioning introduced with Rails 5. The number indicates the migration version the migration was created with, in this case version 5.1 and should be used with Rails versions >= 5.0. This is a class function def self.[](version) of the ActiveRecord::Migration, which calls Compatibility.find(version) and is used for backward compatibility. Here … Read more

Rails – How to use a Helper Inside a Controller

You can use helpers.<helper> in Rails 5+ (or ActionController::Base.helpers.<helper>) view_context.<helper> (Rails 4 & 3) (WARNING: this instantiates a new view instance per call) @template.<helper> (Rails 2) include helper in a singleton class and then singleton.helper include the helper in the controller (WARNING: will make all helper methods into controller actions)

rescue_from ActionController::RoutingError in Rails 4

In application_controller.rb add the following: # You want to get exceptions in development, but not in production. unless Rails.application.config.consider_all_requests_local rescue_from ActionController::RoutingError, with: -> { render_404 } end def render_404 respond_to do |format| format.html { render template: ‘errors/not_found’, status: 404 } format.all { render nothing: true, status: 404 } end end I usually also rescue following … Read more