Giter Site home page Giter Site logo

Comments (13)

pyromaniac avatar pyromaniac commented on May 24, 2024

Can you try to use around_action { |_, &block| Chewy.atomic(&block) } ? Would it help?

from chewy.

rtcoms avatar rtcoms commented on May 24, 2024

No, still getting the same error

from chewy.

pyromaniac avatar pyromaniac commented on May 24, 2024

Try around_action { |block| Chewy.atomic(&block) }
Try

around_action :chewy_atomic
def chewy_atomic &block
  Chewy.atomic(&block)
end

It seems the behavior of around_filter was changed somehow in rails 4.1

from chewy.

rtcoms avatar rtcoms commented on May 24, 2024
around_action { |block| Chewy.atomic(&block) }

givers error

wrong argument type HomeController (expected Proc)

and

around_action :chewy_atomic
def chewy_atomic &block
  Chewy.atomic(&block)
end

givers error

wrong number of arguments (2 for 0..1)

from chewy.

pyromaniac avatar pyromaniac commented on May 24, 2024

Ok, lets research:

around_action :chewy_atomic
def chewy_atomic *args, &block
  p args
  p block
end

from chewy.

rtcoms avatar rtcoms commented on May 24, 2024

args ==> []
block ==> #Proc:0xb20456e8@/home/rtcoms/.rvm/gems/ruby-2.1.0@rails41_upgrade/gems/activesupport-4.1.1/lib/active_support/callbacks.rb:298

from chewy.

pyromaniac avatar pyromaniac commented on May 24, 2024

Ok, I'll try to debug it later

from chewy.

fxn avatar fxn commented on May 24, 2024

Let me add two cents: The public contract for around filters is that they have to yield:

around_action :chewy_atomic

def chewy_atomic
  Chewy.atomic do
    yield
  end
end

That's the way the around action is supposed to be written. Also, in instance methods self is of course the controller in case you need to do anything with it.

from chewy.

pyromaniac avatar pyromaniac commented on May 24, 2024

Xavier, but what have been changed since rails 3 in filters? Why the first approach is not working in 4?

from chewy.

fxn avatar fxn commented on May 24, 2024

Not sure, there seems to be something going on with around filters being called with blocks but I don't see anything related to that. Let me investigate a bit.

from chewy.

fxn avatar fxn commented on May 24, 2024

I ran a bisect and this seems to be a regression in Ruby on Rails introduced by rails/rails@07da960.

@tenderlove does it ring a bell to you?

Test case for Action Pack:

require 'abstract_unit'

module AbstractController
  module Testing
    class CallbackController < AbstractController::Base
      include AbstractController::Callbacks

      around_filter { |controller, &block|
        controller.instance_eval do
          @aroundz = 'FIRST'
        end

        block.call

        controller.instance_eval do
          @aroundz << 'SECOND'
        end
      }

      def index
        @text = 'foo'
        self.response_body = @text
      end
    end

    class TestCallbacks2 < ActiveSupport::TestCase
      def setup
        @controller = CallbackController.new
      end

      test 'around_action with block' do
        @controller.process(:index)

        assert_equal 'FIRSTSECOND', @controller.instance_variable_get('@aroundz')
        assert_equal 'foo', @controller.instance_variable_get('@text')
      end
    end
  end
end

from chewy.

pyromaniac avatar pyromaniac commented on May 24, 2024

Yeah, now I remember, I've faced this previously here: pyromaniac/active_data@6a5def3#diff-187370617b60bc61e60e7ced18a88b66L46 and found a kind of workaround.

from chewy.

rtcoms avatar rtcoms commented on May 24, 2024

Well , code give b y @fxn worked. I was getting error because of something else

around_action :chewy_atomic
def chewy_atomic &block
  Chewy.atomic(&block)
end

from chewy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.