我有这个自定义控制器:
class DownloadsController < ApplicationController
layout 'layouts/rails_admin/application'
def index
end
end
我想使用默认的rails_admin布局。但是在访问索引操作的路径时出现此错误:
undefined local variable or method `dashboard_path' for #<#<Class:0x28a4d68>:0x28a2560>¨
如何使用rails_admin使用的布局?
我需要使用自定义控制器,操作和视图。只需要将它包含在rails_admin中。
答案 0 :(得分:3)
你可以尝试这种方式,但如果这不是最好的做法,请改进它。
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
并覆盖rails admin部分视图,通过创建文件 /app/views/layouts/rails_admin/pjax.html.haml
- 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
答案 1 :(得分:-1)
写
layout 'rails_admin/application'
而不是
layout 'layouts/rails_admin/application'