您可以按照我的方式尝试,但如果这不是最佳做法,请改进。
class DownloadsController < ApplicationController
include ActionView::Helpers::TextHelper
include RailsAdmin::MainHelper
include RailsAdmin::ApplicationHelper
include RailsAdmin::Engine.routes.url_helpers
layout 'layouts/rails_admin/application'
def index
@page_name = "custom" # just for title on template
@is_custom = true # custom marker
end
end
并通过在 /app/views/layouts/rails_admin/pjax.html.haml 中创建文件来覆盖 rails admin 部分视图
- unless @is_custom.eql? true
/ this is default from rails admin, I do not need this for custom controller
:javascript
$('.nav.nav-list li.active').removeClass('active');
$('.nav.nav-list li[data-model="#{@abstract_model.to_param}"]').addClass('active');
%title= "#{@abstract_model.try(:pretty_name) || @page_name} | #{[_get_plugin_name[0] || 'Rails', _get_plugin_name[1] || 'Admin'].join(' ')}"
.page-header
%h1= @page_name
- flash && flash.each do |key, value|
.alert{class: "alert-#{key}"}
%a.close{href: '#', :'data-dismiss' => "alert"}×
= value
= breadcrumb
%ul.nav.nav-tabs
= menu_for((@abstract_model ? (@object.try(:persisted?) ? :member : :collection) : :root), @abstract_model, @object)
= content_for :contextual_tabs
/ just render yield for custom controller
= yield