2

我有这个自定义控制器:

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 中。

4

2 回答 2

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

并通过在 /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
于 2014-03-20T11:10:09.630 回答
-1

layout 'rails_admin/application'

代替

layout 'layouts/rails_admin/application'
于 2013-05-20T17:55:34.500 回答