Tag: applicationcontroller

Rails 3.0引擎 – 在ActionController中执行代码

我正在升级我的Rails插件,使其成为最新3.0RC1版本的引擎,并且我在找出扩展ActionController的最佳(也是最正确的)方法时遇到了一些麻烦。 我已经在DHH上看过这篇文章了, 这个问题在这里,但是我的问题更多的是关于如何在ActionController正确调用代码。 例如,我需要在我的引擎控制器中调用以下内容: class ApplicationController < ActionController::Base helper :all before_filter :require_one_user after_filter :store_location private def require_one_user # Code goes here end def store_location # Code goes here end end 我知道如何正确地包含我的两个私有函数,但我找不到一种方法来正确调用helper , before_filter和after_filter 。 我非常感谢一些链接或方法来使这项工作。 我已经尝试将我的控制器命名为ApplicationController其他东西,并让真正的ApplicationController扩展它,但这似乎也不起作用。 我真的很想找到能让发动机用户的生活变得尽可能简单的任何解决方案。 理想情况下,他们不必扩展我的类,但他们拥有内置于自己的ApplicationController所有function。

如何将操作路由到Rails 3中的应用程序控制器?

我正在使用gem rails3-jquery-autocomplete并且没有任何问题,但是我现在已经将我的自动完成表单移动到应用程序模板中,因此ajax调用现在由应用程序控制器处理,因此我的路由已从以下更改: home/autocomplete_category_name 现在需要删除主页并从以下路径: home_autocomplete_category_name_path 至: autocomplete_category_name_path 有人有任何想法吗? 还在学习Rails的来龙去脉,所以现在这对我来说是个死胡同。 谢谢。

如何在gem中扩展ApplicationController?

我想我会想出一个灵活的方法来扩展Rails 3.x gem中的ApplicationController。 在我的gem的lib/my_namespace/my_controller.rb ,我有: class MyNamespace::MyController < ApplicationController before_filter :some_method after_filter :another_method def initialize # getting classname of the subclass to use for lookup of the associated model, etc. # and storing the model_class in an instance variable # … end # define :some_method, :another_method, etc. # … private attr_accessor :subclass_defined_during_initialize # etc. # […]