ruby-on-rails 将参数传递给around_action会引发:LocalJumpError未给定块(生成)

6l7fqoea  于 2023-02-17  发布在  Ruby
关注(0)|答案(2)|浏览(121)

我想用around_action来 Package 我的操作:

around_action { do_stuff("foo") }

我的around_action如下所示:

def do_stuff(arg)
  some_block do
    Rails.logger.error "arg: #{arg}"
    yield
  end
end

但这会引发一个LocalJumpError no block given (yield)。我做错了什么?

9rbhqvlz

9rbhqvlz1#

我最终解决了它:

around_action -> (controller, block) { do_stuff("foo", block) }

def do_stuff(arg, block)
  some_block do
    Rails.logger.error "arg: #{arg}"
    block.call
  end
end
u0sqgete

u0sqgete2#

我也有同样的问题,但最终发现这个工作:

around_action do :something

def something
  begin
    FOOBAR
    yield
  end
end

相关问题