简体   繁体   English

编写宝石时,如何获得帮助者的访问权限?

[英]When writing a gem, how do you get access to helpers?

For a gem, i'm writing, I want to be able to access current_user (most auth systems have this helper) 对于一个宝石,我正在写,我希望能够访问current_user(大多数身份验证系统都有此帮助器)

What are some ways of doing that? 有哪些方法可以做到这一点?

the thing that the controller includes to get current_user is this AuthenticatedSystem not sure how the helpers get access to it's contents 控制器要获取current_user所包括的是此AuthenticatedSystem不确定助手如何访问其内容

*I'm using RestfulAuth *我正在使用RestfulAuth

If your gem has modules that get included on controllers, you can test if the method is available: 如果您的gem具有包含在控制器中的模块,则可以测试该方法是否可用:

self.respond_to?( :current_user )

And if it is just call it. 如果只是调用它。 If your gem really needs it it would even raise an error if the method is not available. 如果您的宝石确实需要它,如果该方法不可用,它甚至会引发错误。

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

相关问题 在编写gem时如何测试虚拟rails应用程序? - How do you test a dummy rails app when writing a gem? Rails:你如何访问RESTful助手? - Rails: how do you access RESTful helpers? 如何让其他宝石助手进入我的引擎宝石测试? - How to get other Gem helpers into my Engine Gem's tests? 如何从ActionMailer预览中访问视图助手或view_context? - How do you access view helpers or view_context from an ActionMailer preview? 如何将 Rails 视图助手提取到 gem 中? - How do I extract Rails view helpers into a gem? 使用databasedotcom ruby​​ gem访问Salesforce时,如何获取特定用户(或帐户)的ActivityHistory - When using databasedotcom ruby gem to access salesforce, how do I get the ActivityHistory for a particular User (or Account) 如何获得gem上可用的命令列表? - How do you get a list of commands available on a gem? 你怎么得到耐嚼的宝石来过滤结果? - How do you get the Chewy gem to filter results? 在 Rails 中的分页 gem 中,您如何在不需要时隐藏分页? - In pagy gem in rails, how do you hide pagination when unneeded? 当用户已经登录时,如何使用Twitter gem和Omniauth gem获取用户的访问令牌? - How do I fetch the access token for a user using the Twitter gem and the Omniauth gem when the users is already logged in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM