-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How does the model have access to the request environment? #44
Comments
Hey John! If you're using Rails there's a default middleware which sets those vars for the current request: https://github.com/joshfrench/rakismet/blob/master/lib/rakismet/middleware.rb (Which is why you need to call If you're not using Rails, you'd have to adapt that or set those vars manually. |
Gotcha — but where/how in the model does it access those vars? Is that a |
So that middleware sets the current request data as class-level vars on the Then Rakismet has no knowledge of AR, you could include |
Ahhh. So I suppose that means rakismet isn't thread-safe? |
It's not. There's an out-of-date PR that I'd gladly merge if someone wanted to bring that branch up to speed with master: #35 (Hint hint, nudge nudge.) |
Instead of explicitly supporting it with thread-local variables, what do you think of these ideas…
I like 1 a lot better but maybe there are reasons that 2 is more flexible or something. WDYT? |
They're both breaking changes, but in hindsight I think explicitly passing the request data in some form is preferable to magically gleaning it from the environment. The first option would be my choice, as it relieves the user of needing to know which request vars are important. Open question: if I decide to store my own request info -- @comment = Comment.new({ user_ip: foo, ... }) And later I supply a different request env: @comment.spam?({ user_ip: bar, ... }) Which value would you expect to take precedence? |
(hi Josh!)
The readme says:
I chased
user_ip
around the code in a loop and am too stupid to figure out how a model can have access to the request environment. Where does this happen?The text was updated successfully, but these errors were encountered: