ruby-on-rails - 如何更改 Rails 3 Controller 中 View 文件的默认路径?

标签 ruby-on-rails ruby model-view-controller ruby-on-rails-3

我有一个名为 ProjectsController 的 Controller 。默认情况下,它的操作在 app/views/projects 中查找 View 。我想更改所有方法的路径(indexshownewedit 等。 .) 在 Controller 中。

例如:

class ProjectsController < ApplicationController

  #I'd like to be able to do something like this
  views_path 'views/mycustomfolder'

  def index
    #some code
  end

  def show
    #some code
  end

  def new
    #some code
  end

  def edit
    #some code
  end
end

请注意,我并没有用 render 更改每个方法,而是为所有这些方法定义了一个默认路径。这可能吗?如果是,怎么办?

谢谢!

最佳答案

参见 ActionView::ViewPaths::ClassMethods#prepend_view_path .

class ProjectsController < ApplicationController
    prepend_view_path 'app/views/mycustomfolder'
    ...

关于ruby-on-rails - 如何更改 Rails 3 Controller 中 View 文件的默认路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4301249/

相关文章:

javascript - 使用 jquery 引导表单验证

apache - Htaccess : URL Rewriting not causing 404 on nonexisting pages and not working as expected

ruby-on-rails - 将表列添加到 Group by 子句 - Ruby on Rails - Postgresql

ruby - 使用条件正则表达式从 url 生成文件名

ruby-on-rails - 如何在 Elastic Beanstalk 容器中提供 Rails 应用程序的 webpack Assets ?

ruby - 验证和规范化偏序集

mysql - Mysql Gem 中的 Ruby 错误

c# - Rotativa MVC 不在 PDF 上加载 CSS 或图像

ruby-on-rails - Best_in_place 标签槽

ruby-on-rails - Rails 3 "_method=PUT"仍然可以工作吗?