Ruby on rails 一个模型的活动管理显示页面不工作

Ruby on rails 一个模型的活动管理显示页面不工作,ruby-on-rails,ruby,ruby-on-rails-3,activeadmin,Ruby On Rails,Ruby,Ruby On Rails 3,Activeadmin,我正在将Active Admin集成到Ruby on Rails应用程序中。我注册了所有型号,并且已经为所有型号设置了索引、过滤器和显示。一切正常,但对于一种型号,admin/show页面未运行 从admin/index页面调用show页面时,我得到: NoMethodError in Admin/safts#show Showing /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/activeadmin-0.6.0/app/views/

我正在将Active Admin集成到Ruby on Rails应用程序中。我注册了所有型号,并且已经为所有型号设置了
索引
过滤器
显示
。一切正常,但对于一种型号,
admin/show
页面未运行

admin/index
页面调用show页面时,我得到:

NoMethodError in Admin/safts#show

Showing /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/activeadmin-0.6.0/app/views/active_admin/resource/show.html.arb where line #1 raised:

undefined method `empty?' for #<Keyword:0x105498800>
Extracted source (around line #1):

1: insert_tag renderer_for(:show)

Request

Parameters:

{"id"=>"9"}

仅用于上下文:SAFT是一本杂志,包含文本、图像、作者等。所有其他资源都在管理中运行良好。只有SAFT的
显示页面
不工作。可能是什么?

我能够解决这个问题,这与关联有关

gem的DisplayHelper模块必须修改如下:

module ActiveAdmin
  module ViewHelpers
    module DisplayHelper

      # Attempts to call any known display name methods on the resource.
      # See the setting in `application.rb` for the list of methods and their priority.
      def display_name(resource)
        resource.send display_name_method_for resource
      end

      # Looks up and caches the first available display name method.
      def display_name_method_for(resource)
        @@display_name_methods_cache ||= {}
        @@display_name_methods_cache[resource.class] ||= begin
          methods = active_admin_application.display_name_methods - association_methods_for(resource)
          methods.detect{ |method| resource.respond_to? method }
        end
      end

      # To prevent conflicts, we exclude any methods that happen to be associations.
      def association_methods_for(resource)
        return [] unless resource.class.respond_to? :reflect_on_all_associations
        resource.class.reflect_on_all_associations.map(&:name)
      end

      # Return a pretty string for any object
      # Date Time are formatted via #localize with :format => :long
      # ActiveRecord objects are formatted via #auto_link
      # We attempt to #display_name of any other objects
      def pretty_format(object)
        case object
        when String
          object
        when Arbre::Element
          object
        when Date, Time
          localize(object, :format => :long)
        when ActiveRecord::Base
          auto_link(object)
        else
          display_name(object)
        end
      end
    end
  end
end

这是因为在SAFT模型中,存在与名称
title
的关联,这与display\u name\u方法冲突。

您的日志条目显示关键字不响应
Pages::Show#default\u title
中的
empty?
default\u title
调用
display\u name
,是否覆盖了
display\u name\u方法
?在这种情况下,您可以删除
:title

config/initializers/active\u admin
中:

config.display_name_methods = [ :display_name,
                                  :full_name,
                                  :name,
                                  :username,
                                  :login,
                                  :email,
                                  :to_s ]
在这种情况下,您还可以尝试显式设置标题,例如

  show title: :short do ...

我注意到你在Rails和ActiveAdmin的老版本上,我希望你会考虑。非常不幸的是,ActiveAdmin没有给出一个错误来指导您在我的回答中选择自定义选项。您不是第一个或最后一个遇到这种情况的人:-(谢谢Piers!我昨天在Github上发现了一个提示,可能是您做的,通过遵循它,我成功地使它工作了!现在我正在处理灰显的“批处理操作”。。。
module ActiveAdmin
  module ViewHelpers
    module DisplayHelper

      # Attempts to call any known display name methods on the resource.
      # See the setting in `application.rb` for the list of methods and their priority.
      def display_name(resource)
        resource.send display_name_method_for resource
      end

      # Looks up and caches the first available display name method.
      def display_name_method_for(resource)
        @@display_name_methods_cache ||= {}
        @@display_name_methods_cache[resource.class] ||= begin
          methods = active_admin_application.display_name_methods - association_methods_for(resource)
          methods.detect{ |method| resource.respond_to? method }
        end
      end

      # To prevent conflicts, we exclude any methods that happen to be associations.
      def association_methods_for(resource)
        return [] unless resource.class.respond_to? :reflect_on_all_associations
        resource.class.reflect_on_all_associations.map(&:name)
      end

      # Return a pretty string for any object
      # Date Time are formatted via #localize with :format => :long
      # ActiveRecord objects are formatted via #auto_link
      # We attempt to #display_name of any other objects
      def pretty_format(object)
        case object
        when String
          object
        when Arbre::Element
          object
        when Date, Time
          localize(object, :format => :long)
        when ActiveRecord::Base
          auto_link(object)
        else
          display_name(object)
        end
      end
    end
  end
end
config.display_name_methods = [ :display_name,
                                  :full_name,
                                  :name,
                                  :username,
                                  :login,
                                  :email,
                                  :to_s ]
  show title: :short do ...