Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 6.1 will return Content-Type header without modification ... use `#media_type` instead

What does this deprecation message mean for me to change when it references this block?

def json_response(object, status = :ok)
  render json: object, status: status
end

Edit

The message:

Rails 6.1 will return Content-Type header without modification … use #media_type instead

like image 784
t56k Avatar asked Jul 28 '19 02:07

t56k


4 Answers

I got the same error message when I was upgrading my app from Rails 5.2.3 to Rails 6.0.0-rc1

config/application.rb

# this was the line before
# config.load_defaults 5.2
config.load_defaults 6.0

In my case I had to change the version from 5.2 to 6.0

like image 186
user1722721 Avatar answered Oct 06 '22 00:10

user1722721


You can make the warning go away by adding this to your application.rb:

config.action_dispatch.return_only_media_type_on_content_type = false

You would need to make sure that if you are using content_type anywhere in your code that you replace that with media_type before making that change.

like image 29
Jan M Avatar answered Oct 06 '22 00:10

Jan M


I also got the same error message when I was upgrading my app from Rails 5.2.4 to Rails 6.0.2.1.

For me the error was being caused by an older version of Turbolinks.

Upgrading from Turbolinks 5.1.0 to 5.2.1 made the warning go away.

like image 34
James Hibbard Avatar answered Oct 06 '22 00:10

James Hibbard


After upgrade from Rails 5.2 to Rails 6.0.3.1 beside config.load_defaults, mentioned by user1722721, i had to add config.autoloader = :classic to application.rb for correct loading:

# config/application.rb
module YourAppName
  class Application < Rails::Application
    config.load_defaults 6.0
    config.autoloader = :classic
    # ...
  end
end
like image 44
Yurii Verbytskyi Avatar answered Oct 05 '22 22:10

Yurii Verbytskyi