仪表板的单独模板



我需要为仪表板使用一个单独的模板。如此......以至于......http://mysite/dashboard加载一个完全不同的模板。

所以,我在layouts/dashboard_template.html下创建了一个模板。erb

我的仪表盘控制器

class DashboardController < ApplicationController
  def index
    render template: 'layouts/dashboard_template.html.erb'  
  end
end

我增加了以下路线。rb

get 'dashboard', to: 'dashboard#index'

但是,它在application.html.erb中加载模板!不知道该怎么修理它。希望这是清楚的。请帮助。

在您的仪表板控制器中使用

class DashboardController < ApplicationController
  layout :set_layout, only: [:index]
  def index
    # do your stuff
  end
  def set_layout
    "layout_file_name" || 'application'
  end
end

这将加载你的布局,如果存在,否则主应用程序布局

最新更新