LoginSignup
6
7

More than 5 years have passed since last update.

before_filterに引数を渡す

Posted at

基本的にfilterで呼び出すメソッドに引数は渡せません。
しかし、ちょっと工夫することでそれに相当するものを作ることはできます。

class FooController < ApplicationController
  before_filter(:only => [ :show ]), lambda {|controller|
    controller.foo_filter(true, false)
  }

  def foo_filter(a, b)
    head :not_found unless a && b
  end
  private :foo_filter
end

ちょっと見栄えは良くないですね。

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7