`
orcl_zhang
  • 浏览: 233837 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Rails: Calling render() outside your Controllers

阅读更多
From:http://blog.choonkeat.com/weblog/2006/08/rails-calling-r.html

module RenderAnywhere
    
    class DummyController
        def logger
            RAILS_DEFAULT_LOGGER
        end
        def headers
            {}
        end
    end
    
    def render(options, assigns = {})
        viewer = ActionView::Base.new(Rails::Configuration.new.view_path, assigns, DummyController.new)
        viewer.render options
    end
    
    def template_exists?(path, assigns = {})
        viewer = ActionView::Base.new(Rails::Configuration.new.view_path, assigns, DummyController.new)
        viewer.pick_template_extension(path) rescue false
    end
end

分享到:
评论
1 楼 orcl_zhang 2011-05-02  
这个并不是一个很好的办法,这样会使render的速度慢很多,非常非常慢,不如把要render的html硬写到方法里。

相关推荐

Global site tag (gtag.js) - Google Analytics