PKul
PKul

Reputation: 1711

Rails: How to replace :if and :unless option for rails 5.2

in application_controller.rb:4

class ApplicationController < ActionController::Base
  before_action :prepare_meta_tags, if: "request.get?"

Rails 5.1 WARNING

DEPRECATION WARNING: Passing string to be evaluated in :if and :unless conditional options is deprecated and will be removed in Rails 5.2 without replacement. Pass a symbol for an instance method, or a lambda, proc or block, instead. (called from <class:ApplicationController> at MYSITE/app/controllers/application_controller.rb:4)

Question:

  1. What is option in :if and :unless in that clause to be rewrite
  2. And how to rewrite for compliance with rails 5.2

I have if and unless all over in my project. Need advice. Thanks

Upvotes: 19

Views: 5483

Answers (1)

khaled_gomaa
khaled_gomaa

Reputation: 3412

First of all, don't worry they are not deprecating :if and :unless. They are deprecating passing a string to it.

Using lambda instead is way better in this case

class ApplicationController < ActionController::Base
  before_action :prepare_meta_tags, if: -> { request.get? }
...
end

Upvotes: 43

Related Questions