0

I want to wrap my action in this around_action:

around_action { do_stuff("foo") }

My around_action looks like this:

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

But this raises a LocalJumpError no block given (yield). What am I doing wrong?

JohnSmith1976
  • 536
  • 2
  • 12
  • 35
  • 1
    Checkout https://stackoverflow.com/a/20561223/398863 where you will find different ways to specify block in `around_action` – Amit Patel Mar 25 '19 at 11:38
  • 1
    This should help you - https://stackoverflow.com/a/18623495/4614833 – Sinscary Mar 25 '19 at 12:04
  • Sorry, but I've tried various approaches based on the answers you both linked to, but none works. – JohnSmith1976 Mar 25 '19 at 13:44
  • Basically you are not passing any block to the `do_stuff` method so you are getting [LocalJumpError](https://ruby-doc.org/core-2.3.0/LocalJumpError.html). I don't understand the purpose of `do_stuff`. Is this method being called from elsewhere other than `around_filter`? – Amit Patel Mar 25 '19 at 18:26
  • @AmitPatel the `do_stuff` is just an example, but in order to not distract I've left it simple and useless. But if you're saying I'm not passing any block, please show me how to do that. – JohnSmith1976 Mar 25 '19 at 19:20

2 Answers2

1

I ended up solving it with:

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
JohnSmith1976
  • 536
  • 2
  • 12
  • 35
0

I had the same issue but eventually found this to work:

around_action do :something

def something
  begin
    FOOBAR
    yield
  end
end
Matt16749
  • 119
  • 11