upgrade - bundler

after upading bundler, following changes is required:

  1. Remove the 'quiet asset' gem from your Gemfile, as it is no longer supported or needed in Rails 5. Rails introduce - > config.assets.quiet = true

  2. require 'bootsnap/setup' # Speed up boot time by caching expensive operations.

  3. `Rails.application.config.middleware.insert_before 0, Rack::Cors do allow do origins '*'

resource '*', :headers => :any, :methods => [:get, :post, :options, :delete, :put]

resource '/microservice/', :headers => :any, :methods => [:get, :post, :options, :delete, :put] resource '/api/messengers/', :headers => :any, :methods => [:get, :post, :options, :delete, :put] end end`

this code is moved to config/initializers/cors.rb from rails 4 application.rb according rails 5 setup doc.

  1. //= require jquery-ui/autocomplete//= require jquery-ui/widgets/autocomplete

//= require rails-ujs //# jquery_ujs is replaced by rails-ujs in rails 5

jQuery UJS relies on jQuery's style of Unobtrusive JavaScript (UJS) API, which means it integrates closely with jQuery for AJAX operations and other interactive features. In contrast, Rails UJS operates with vanilla JavaScript, eliminating the dependency on jQuery. This shift impacts existing AJAX functionalities that were designed with jQuery UJS's unobtrusive JavaScript approach in mind.

  1. //= require filterrific/filterrific-jquery to //= require filterrific/filterrific filterrific is pure js since version 5, js only higher version works well with rails 5

  2. For YAML condition rails 5 use Psych and in turn Psych use safe_load with aliases: true in aliasing

if Psych::VERSION > '4.0' @@conditions = YAML.safe_load(File.read(CONFIG_FILE), aliases: true) else @@conditions =YAML.load(File.read(CONFIG_FILE)) end

  1. remove all the before_filter(deprecated in rails 5) with new syntax before_action

Significant change: TIme zone. Psych::DisallowedClass - Tried to load unspecified class: ActiveSupport::TimeWithZone: app/controllers/doctors/sessions_controller.rb:33:in ‘destroy'

  1. Rails 5 now handle time with zone→ ActiveSupport::TimeWithZone https://danilenko.org/2012/7/6/rails_timezones/

while rails 4 , add time in column as Time.now → which can be problematic with adding time from different zone (e.g → )

  1. Turbolinks is updated to 5 from 2.5

Turbolinks has been upgraded from version 2.5 to 5, leading to notable changes in how page reloads or redirects handle JavaScript. Specifically, when only parts of the page are reloaded, some JavaScript that relies on the $(document).ready event may not execute as expected, potentially causing issues such as unresponsive tabs or features. It's important to note that all versions of Turbolinks update only parts of the page, but the focus here is on how JavaScript execution is affected by the new page lifecycle management features introduced in Turbolinks These changes are a result of Turbolinks undergoing significant technical evolutions from version 2.5 to 5. The issues described are directly impacted by new page lifecycle management features introduced in Turbolinks 5, including turbolinks:load, turbolinks:visit, turbolinks:request-start, and turbolinks:before-cache. For example, when Turbolinks loads part of the page, dependent scripts that were loaded with the $(document).ready event in jQuery might not be re-executed since the page is only partially reloaded by Turbolinks. These events introduced by Turbolinks must be utilized to ensure proper execution of JavaScript. In cases where links use Turbolinks for reloading (e.g., a navigation bar), it might be necessary to disable Turbolinks (data-turbolinks="false") to ensure that all JavaScript is fully reloaded. Additionally, in some instances, scripts that traditionally run on $(document).ready must be complemented with code that hooks into Turbolinks events to ensure supporting new behavior and backward compatibly :

// Example showing how to initialize JavaScript handlers for both jQuery's document ready and Turbolinks' load event
$(document).ready(function() {
  initializeErx2Handlers();
});

$(document).on('turbolinks:load', function() {
  initializeErx2Handlers();
});

This approach ensures that JavaScript functionalities remain consistent and fully operational across both initial page loads and subsequent navigations facilitated by Turbolinks.

Breaking Changes

1. Timezone

Time.now  → Time.zone.now

Rails 5 introduced a significant change in handling time objects by using ActiveSupport::TimeWithZone instead of plain Ruby Time objects. This change ensures better handling of time zones in applications. Previously, dealing with time zones involved manual conversions between local times and UTC, which was error-prone and complex.

With ActiveSupport::TimeWithZone, time is stored in UTC in the database and automatically converted to the application's time zone when loaded. This approach simplifies time zone management, as there's no need for manual conversions. The application's time zone can be set, and Rails handles the rest. For example:

# Set application's time zone Save to grepper

Time.zone = 'America/Chicago'

When retrieving a timestamp from the database, Rails automatically represents it in the set time zone

created_at = Foo.last.created_at # => Tue, 31 Dec 2019 17:16:14 CST -06:00

The actual stored value in the database is in UTC

utc_time = Foo.last.created_at.utc # => 2019-12-31 23:16:14 UTC

This update makes handling times and time zones more robust and less error-prone, as Rails automatically manages the conversion to and from UTC, aligned with the application's configured time zone. This approach eliminates the complexities and bugs associated with manual time conversions.

2. searchkick 2.4.0 → searchkick 5.2.4

Searchkick, upgraded into 5.2.4 which has breaking changes since version 4

Since version 4, searchkick requires either elasticsearch or opensearch-ruby gems, among other changes.

Elasticsearch 8.12.0 upgrade

rails searchkick_reindex:users for reindexing user in batches


curl --cacert ~/.es/http_ca.crt -u username:password -X GET "[<https://localhost:9200/_cluster/settings?include_defaults=true&pretty>](<https://localhost:9200/_cluster/settings?include_defaults=true&pretty>)"``` 

To adjust the disk watermarks on your Elasticsearch cluster, you can use the following curl command:

curl --cacert ~/.es/http_ca.crt -u username:password -X PUT "<https://localhost:9200/_cluster/settings>" -H "Content-Type: application/json" -d'
{
"persistent": {
"cluster.routing.allocation.disk.watermark.low": "85%",
"cluster.routing.allocation.disk.watermark.high": "90%",
"cluster.routing.allocation.disk.watermark.flood_stage": "95%"
}
}'

This will set the low disk watermark at 85%, the high disk watermark at 90%, and the flood stage disk watermark at 95%. These settings determine how Elasticsearch responds when your disk reaches certain storage capacity thresholds.

3. Credentials implementation (rails 5.2 and above)

Rails Master Key Management

Overview

This document outlines updated procedures for managing the Rails master key, particularly in light of the need for a 32-character key in Rails 5.2. The key length requirement is crucial for compatibility with Rails' encryption system.

Updated Master Key Generation (Custom)

Generating a Valid Master Key

Master Key Replacement

Replacing an Existing Master Key

  1. Replace the Key:
  2. Edit Credentials with New Key:

Security and Backup

Key Security

Backup

Deployment and CI/CD Integration

Updating Environment Variables

3. In Rails 5, rails-ujs is default replacing Jquery-ujs

Significant Impacts

While migrating from jQuery-UJS to Rails-UJS, you might encounter a few surprises. For instance, with jQuery-UJS, AJAX event handlers return a jQuery event. However, Rails-UJS returns a native JavaScript event. This difference can cause issues when you migrate your AJAX event handlers.

For example, jQuery-UJS event handlers stop the propagation of the event to parent elements when you return false. This behavior is not the same with Rails-UJS.

To prevent propagation in Rails-UJS, you will need to explicitly call the stopPropagation method on the event object:

document.body.addEventListener('ajax:success', function(event) {
  // Your code here...
  event.stopPropagation();
});

Similarly, to prevent the default action from occurring, you will need to explicitly call the preventDefault method:

document.body.addEventListener('ajax:success', function(event) {
  // Your code here...
  event.preventDefault();
});

By being aware of these differences, you can ensure a smoother transition from jQuery-UJS to Rails-UJS.

4. ActionController::Parameters no longer inherit ruby hash or array

Change: In Rails 5, ActionController::Parameters now returns an object instead of a hash, impacting how you access parameters in your controllers.

Impacts

Solutions:

  1. Use to_h after permitting:
  2. Use to_unsafe_h (caution):
  3. Always permit parameters:

Additional notes:

Example:

Ruby

`def do_something_with_params# Option 1: Permit and then convert to hash permitted_params = params.permit(:name, :email).to_h

Option 2 (caution): Use to_unsafe_h for safe params

params.to_unsafe_h.slice(:name, :email) # Not recommended for user-supplied data

Do something with permitted_params

end`

ActionController::Parameters conversion

In Rails 5, ActionController::Parameters no longer inherits from Ruby's Hash, which can cause issues when you attempt to use hash methods such as count directly on the params object. This is the root of the problem in the modify_medicince_params method you have. Here's the original method: