Is “proc” required with conditional before_action/before_filter?

后端 未结 4 1134
你的背包
你的背包 2021-02-05 00:05

Behold, a before_filter:

class ThingController < ApplicationController
  before_filter :check_stuff, :if => proc {Rails.env.production?}
end
<         


        
4条回答
  •  心在旅途
    2021-02-05 00:55

    I would recommend using staby lambda. If you want know, WHY? Please read this

    class ThingController < ApplicationController
      before_action :check_stuff, if: -> { Rails.env.production? }
    end
    

    which is almost equivalent to Upvote Me's answer.

提交回复
热议问题