rails user-ip from within the model?
I'm wondering if there's a more direct way to get and record a users IP in the model itself. I've been doing it from the controller but I noticed using the rakismet gem it mentions doing everything from within the model, but not the IP specifically.
http://github.com/joshfrench/rakismet
Currently I'm doing this, just before I save from the controller. It works fine.
@notification = Notification.new(params[:notification].merge(:user_ip => request.remote_ip, :user_agent => request.user_agent, :referrer => request.ref开发者_运维知识库errer))
I think this little trick might be what you're looking for: http://rails-bestpractices.com/posts/47-fetch-current-user-in-models
Strictly speaking it's a violation of the MVC pattern, so it should be used carefully.
精彩评论