如何在 rails 3.2 (ActionView::PathSet) 中添加 rails 视图路径 [英] How to prepend rails view paths in rails 3.2 (ActionView::PathSet)

查看:33
本文介绍了如何在 rails 3.2 (ActionView::PathSet) 中添加 rails 视图路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将视图添加到 rails 视图数组中,例如

I am trying to prepend views to the rails view array e.g.

prepend_view_path("#{Rails.root}/app/views/custom/blah")

prepend_view_path("#{Rails.root}/app/views/custom/blah")

这很好用,但是在我的测试套件中我一直看到

This works fine, however in my test suite I keep seeing

弃用警告:process_view_paths 已弃用,将从 Rails 3.2 中删除.

经过一些研究,我看到提到 ActionView::PathSet,但在搜索 google 或 Rails API 文档中找不到任何帮助.我需要知道如何使用这种在 rails 3.2 中添加路径的新方法

After a bit of research I see mention of ActionView::PathSet, but cannot find any help searching google or in the Rails API documentation. I need to know how to use this new way of prepending paths in rails 3.2

我真的很想摆脱这个警告.有什么想法吗?

I would really like to get rid of this warning. Any thoughts?

推荐答案

如果是动态的(基于每个请求设置):

If it is dynamic (set on a per-request basis):

class ApplicationController < ActionController::Base
  before_filter :set_view_path

  def set_view_path
    prepend_view_path "#{Rails.root}/app/views/custom/blah"
  end  
end

我认为它转到了 AbstractController::ViewPaths,但仍然可以从控制器获得 - 应该不会被弃用.

I think it went to AbstractController::ViewPaths, but still available from controller - should be without deprecation.

如果您预先添加静态固定路径:

If you prepend static fixed path:

# config/application.rb    
config.paths.app.views.unshift("#{Rails.root}/app/views/custom/blah")

这篇关于如何在 rails 3.2 (ActionView::PathSet) 中添加 rails 视图路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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