简体   繁体   English

如何从Rails gem或lib中访问会话和cookie?

[英]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 玩笑

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在ruby on rails中使用rubypython gem,如何从lib文件夹调用python脚本? - Using the rubypython gem in ruby on rails, how do you call a python script from the lib folder? 会话和cookie如何在Rails中运行? - How do sessions and cookies work in Rails? 您如何在Rails 4测试中访问cookie的“过期”值? - How do you access cookies “expires” value in Rails 4 tests? 您如何从Rails控制台内的公共活动gem访问活动? - How do you access activities from the public activity gem inside the rails console? 如何从我的Rails 3应用程序的/ lib /文件夹中的ruby脚本中访问我的某个模型? - How do I access one of my models from within a ruby script in the /lib/ folder in my Rails 3 app? 如何从rails gem读取应用程序的cookie - How to read cookies of an application from a rails gem 为什么Rails / lib模块会阻止加载gem模块? - Why do Rails /lib modules prevent gem modules from loading? 如何配置 Rails Gem (TrueMail) - How do you configure a Rails Gem (TrueMail) 如何从引擎中访问主Rails主应用控制器? - How do you access main Rails main app controllers from within an engine? 对于Rails Aws Gem版本2,如何配置它以使用访问密钥? - With Rails Aws Gem version 2, how do you configure it to use your access keys?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM