[英]How do you access sessions and cookies from within a Rails gem or lib?
Im trying to create what will eventually be a rails gem (right now I have the files within the /lib directory) and I need to be able to read/write to and from cookies and sessions. 我试图创建最终将成为rails gem的东西(现在我有/ lib目录中的文件),我需要能够读取/写入cookie和会话。 My methods will be called from within either the controller or views, so access to the cookies and sessions SHOULD be possible from within my gem but I cant figure out how to do it.
我的方法将在控制器或视图中调用,因此应该可以从我的gem中访问cookie和会话,但我无法弄清楚如何去做。
Ive tried extending ActionController to include my module as well as including ActionController inside my module and nothing works. 我已经尝试扩展ActionController以包含我的模块以及在我的模块中包含ActionController并且没有任何作用。 It could be the way Im running my tests since I feel like I have more success when trying to access my module and classes from within console.
它可能是我运行我的测试的方式,因为我觉得我在尝试从控制台中访问我的模块和类时有更多的成功。
Does anyone have any examples of accessing cookies and sessions from within gems/plugins etc? 有没有人有任何从gems /插件等访问cookie和会话的例子?
Thanks, 谢谢,
Josh 玩笑
请参阅https://github.com/hassox/warden/blob/master/lib/warden/session_serializer.rb#L6中的 session=env['rack.session']
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.