Rails引擎中的助手 [英] Helpers in Rails engine

查看:80
本文介绍了Rails引擎中的助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Rails引擎,但是助手有问题.

I am working on a rails engine and I have a problem with the helpers.

显然,这是一个已知的问题",但目前还没有很多解决方案.问题是我有一个想全局访问的AuthenticationHelper,但是它不起作用.

Apparently this is a known "problem" but there's not a lot of solutions out there. The problem is that I have an AuthenticationHelper which I want to access globally - but it's not working.

已阅读到可以在其中添加几行您的init.rb ,但似乎没有任何效果.

I've read that you could add a few lines to your init.rb but it does not seem to have any effect.

您知道在引擎中使应用程序可用的最佳方法是什么吗?

Any idea what the best way to make an application available in an engine?

已修复-只需将代码(来自链接)放在engine.rb中即可.

Fixed it- Just put the code (from the link) in the engine.rb instead.

推荐答案

将此代码放在engine.rb中:

Put this code in engine.rb:

config.to_prepare do
  ApplicationController.helper(MyEngineHelper)
end

这篇关于Rails引擎中的助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆