I have migrated my web app from ruby 2.1 and rails 4.0 to ruby 2.4.9p362 and rails Rails 5.2.4.
When trying to login it worked perfect before, but after migration I get next error message:
Started OPTIONS "//login" for 127.0.0.1 at 2019-11-29 11:47:06 +0100
Processing by ApplicationController#index as */*
Completed 500 Internal Server Error in 24ms (ActiveRecord: 0.0ms)
ActionView::MissingTemplate (Missing template application/index with {:locale=>[:en], :formats=>[:html, :text, :js, :css, :ics, :csv, :vcf, :vtt, :png, :jpeg, :gif, :bmp, :tiff, :svg, :mpeg, :mp3, :ogg, :m4a, :webm, :mp4, :otf, :ttf, :woff, :woff2, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip, :gzip], :variants=>[], :handlers=>[:raw, :erb, :html, :builder, :ruby]}. Searched in:
* "/Users/Rober/Projects/yanpy/dev/yanpyapi/app/views"
):
app/controllers/application_controller.rb:12:in `index'
This is my application_controller:
class ApplicationController < ActionController::Base
before_action :set_headers
def index
render nothing: true
end
def set_headers
if request.headers["HTTP_ORIGIN"]
# better way check origin
# if request.headers["HTTP_ORIGIN"] && /^https?:\/\/(.*)\.some\.site\.com$/i.match(request.headers["HTTP_ORIGIN"])
headers['Access-Control-Allow-Origin'] = request.headers["HTTP_ORIGIN"]
headers['Access-Control-Expose-Headers'] = 'ETag'
headers['Access-Control-Allow-Methods'] = 'GET, POST, PATCH, PUT, DELETE, OPTIONS, HEAD'
headers['Access-Control-Allow-Headers'] = '*,x-requested-with,Content-Type,If-Modified-Since,If-None-Match,Auth-User-Token'
headers['Access-Control-Max-Age'] = '86400'
headers['Access-Control-Allow-Credentials'] = 'true'
end
end
#def set_csrf_cookie_for_ng
# cookies['XSRF-TOKEN'] = form_authenticity_token if protect_against_forgery?
#end
#protected
# def verified_request?
# super || form_authenticity_token == request.headers['X_XSRF_TOKEN']
# end
end
I guessed something changed with the new versions.
render :nothing
has been deprecated in 5.0
https://guides.rubyonrails.org/5_0_release_notes.html#action-pack-deprecations
Deprecated :nothing option for render method.
You're supposed to call
head :ok
The PR mentioned explains why:
head method works similar to render method with :nothing option
You're probably on version 5.1 or higher.
Next time - upgrade to .0 version, fix deprecation notifications, and after that upgrade to .1 and higher.