Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 基于主题创建视图的最佳方法_Ruby On Rails - Fatal编程技术网

Ruby on rails 基于主题创建视图的最佳方法

Ruby on rails 基于主题创建视图的最佳方法,ruby-on-rails,Ruby On Rails,我需要为我拥有的控制器创建单独的视图页 我有一个CustomerController,根据我需要创建自定义页面的客户,这些页面必须存储为文件,而不是来自数据库 所以通常我会这样: class CustomerController < ApplicationController def show @customer = Customer.find(param["id"]) end end 我想做的是让查看页面如下所示: /views/customer/1/show.html

我需要为我拥有的控制器创建单独的视图页

我有一个CustomerController,根据我需要创建自定义页面的客户,这些页面必须存储为文件,而不是来自数据库

所以通常我会这样:

class CustomerController < ApplicationController
  def show
    @customer = Customer.find(param["id"])
  end
end
我想做的是让查看页面如下所示:

/views/customer/1/show.html.erb
/views/customer/2/show.html.erb
/views/customer/3/show.html.erb
如何引用要从操作中加载的特定视图页面?
是否有方法将值1、2、3传递到视图文件夹路径?

您可以在“显示”操作中指定要渲染的模板。Rails将在不显式调用render的情况下呈现对应于该特定操作的模板…因此,在您的情况下,它将自动呈现customers/show.html.erb注意:您的控制器应该是复数的…即CustomerController,而不是CustomerController

若要覆盖此项,可以执行以下操作

def show
  @customer = Customer.find(params[:id])
  render "customers/#{@customer.id}/show.html.erb"
end

文件夹编号也是记录的Id吗?
def show
  @customer = Customer.find(params[:id])
  render "customers/#{@customer.id}/show.html.erb"
end