DEV Community

Discussion on: React Context pattern in Rails

 
silva96 profile image
Benjamín Silva • Edited

using that gem you don't even need the with block thing.

you can for example in the controller:

RequestLocals[:request] = request
Enter fullscreen mode Exit fullscreen mode

and then in the model:

if RequestLocals[:request].remote_ip == some_ip
  ...do something
end
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
thevtm profile image
Vinícius Manjabosco

I agree that request_store_rails would be an alternative solution for my problems.

Maybe I'm missing something but the with block is the "clean up mechanism".

    def with(request_value)
      if get.present?
        raise ContextAlreadyDefinedError,
          "Context already defined!"
      end

      begin
        @@request_value.value = request_value
        yield
      ensure
        @@request_value.value = nil # "clean up mechanism"
      end
    end
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
silva96 profile image
Benjamín Silva

totally, my bad!