代码之家  ›  专栏  ›  技术社区  ›  Patrick Klingemann

如何从插件帮助程序呈现插件中的部分

  •  0
  • Patrick Klingemann  · 技术社区  · 15 年前

    我的插件中有一个助手 测试插件/lib/test_helper.rb :

    module TestHelper
      def test_render
        render 'test_plugin/test_partial'
      end
    end
    

    我有一部分 测试插件/app/views/test插件/test部分.html.erb :

    <p>Hello World!</p>
    

    在我的申请中 应用程序/视图/测试/index.html.erb 当我这样做的时候:

    <%= test_render %>
    

    我得到以下错误:

    缺失部分 测试插件/测试部分 :locale=>[:en,:en], :formats=>[:html],:handlers=>[:rjs, :rhtml,:haml,:builder,:rxml,:erb] 视图路径 “/home//workspace/my_application/app/views”

    1 回复  |  直到 15 年前
        1
  •  1
  •   Paweł Gościcki Ywain    15 年前

    vendor/plugins/test_plugin/app/views/test_plugin

    require 'test_plugin'
    

    require 'test_plugin_helpers'
    
    # Helpers will be available in all controllers
    ActionController::Base.send :include, TestPlugin::Helpers
    
    # Helpers will be available in the views
    ActionView::Base.send :include, TestPlugin::Helpers
    

    module TestPlugin
      module Helpers
        def test_render
          render 'test_plugin/test_partial'
        end
      end
    end
    

    Yuppie!
    

    <%= test_render %>