某个模型的Active Admin Show页面无效

时间:2018-02-25 14:03:43

标签: ruby-on-rails ruby ruby-on-rails-3 activeadmin

我正在将Active Admin集成到Ruby on Rails应用程序中。我注册了所有模型,并为所有模型设置了indexfiltershow。一切正常,但对于一个模型,admin/show页面没有运行。

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

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"}

我的日志文件中的相对条目是:

Started GET "/admin/safts/9" for 127.0.0.1 at Sun Feb 25 14:48:04 +0100 2018
Processing by Admin::SaftsController#show as HTML
  Parameters: {"id"=>"9"}
  [1m[35mAdminUser Load (0.6ms)[0m  SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`id` = 2 LIMIT 1
  [1m[36mSaft Load (0.2ms)[0m  [1mSELECT `safts`.* FROM `safts` WHERE `safts`.`id` = ? LIMIT 1[0m  [["id", "9"]]
  [1m[35mKeyword Load (0.3ms)[0m  SELECT `keywords`.* FROM `keywords` WHERE `keywords`.`id` = 138 LIMIT 1
  Rendered /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/activeadmin-0.6.0/app/views/active_admin/resource/show.html.arb (3.1ms)
Completed 500 Internal Server Error in 10ms

ActionView::Template::Error (undefined method `empty?' for #<Keyword:0x1052a0890>):
1: insert_tag renderer_for(:show)
  activemodel (3.2.5) lib/active_model/attribute_methods.rb:407:in `method_missing'
  activerecord (3.2.5) lib/active_record/attribute_methods.rb:149:in `method_missing'
  activeadmin (0.6.0) lib/active_admin/views/pages/show.rb:38:in `default_title'
  activeadmin (0.6.0) lib/active_admin/views/pages/show.rb:14:in `title'
  activeadmin (0.6.0) lib/active_admin/views/pages/base.rb:25:in `build_active_admin_head'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:49:in `within'
  activeadmin (0.6.0) lib/active_admin/views/pages/base.rb:24:in `build_active_admin_head'
  activeadmin (0.6.0) lib/active_admin/views/pages/base.rb:9:in `build'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:30:in `build_tag'
  arbre (1.0.1) lib/arbre/context.rb:92:in `with_current_arbre_element'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:26:in `build_tag'
  arbre (1.0.1) lib/arbre/element/builder_methods.rb:39:in `insert_tag'
  activeadmin (0.6.0) app/views/active_admin/resource/show.html.arb:1:in `___sers__tephan__rvm_gems_ruby_______p____saftzine_gems_activeadmin_______app_views_active_admin_resource_show_html_arb___1026777847_2195984600'
  arbre (1.0.1) lib/arbre/context.rb:45:in `instance_eval'
  arbre (1.0.1) lib/arbre/context.rb:45:in `initialize'
  activeadmin (0.6.0) app/views/active_admin/resource/show.html.arb:1:in `new'
  activeadmin (0.6.0) app/views/active_admin/resource/show.html.arb:1:in `___sers__tephan__rvm_gems_ruby_______p____saftzine_gems_activeadmin_______app_views_active_admin_resource_show_html_arb___1026777847_2195984600'
  actionpack (3.2.5) lib/action_view/template.rb:145:in `send'
  actionpack (3.2.5) lib/action_view/template.rb:145:in `render'
  activesupport (3.2.5) lib/active_support/notifications.rb:125:in `instrument'
.
.
.
  script/rails:6:in `gem_original_require'
  script/rails:6:in `require'
  script/rails:6


  Rendered /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.7ms)
  Rendered /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.6ms)
  Rendered /Users/xxxxxx/.rvm/gems/ruby-1.8.7-p374@xxxxxx/gems/actionpack-3.2.5/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (9.8ms)

rails模型是:

class Saft < ActiveRecord::Base
    attr_accessible :colour, :cover_alt, :description, :number, :short, :title_id

# Associations
    has_and_belongs_to_many :keywords, :join_table => "safts_keywords" 
    has_many :authors, :through => :texts 
    has_many :texts 
    belongs_to :title, :class_name => "Keyword", :foreign_key => "title_id"
    has_one :cover
    has_many :stamps
    has_many :images
end

ActiveAdmin资源是:

ActiveAdmin.register Saft do
    index do
        column "Issue", :number 
        column "Title", :title_id do |saft|
            link_to saft.title.word.capitalize, saft_path(saft)
        end
        column :short
        column :description
        column :colour
        column :cover_alt
        default_actions
    end

    # Filter only by:
    filter :title_id, :label => 'Title', :as => :select, :collection => Saft.all.map{|u| ["#{u.title.word.capitalize}", u.id]}
    filter :short

    form do |f|
        f.inputs "Saft Details" do
            f.input :number, :label => "Number of issue"
            f.input :title_id, :label => 'Title', :as => :select, :collection => Keyword.all.map{|u| ["#{u.word.capitalize}", u.id]}
            f.input :short
            f.input :description
            f.input :colour, :label => "Colour (in hex)"
            f.input :cover_alt
        end
        f.actions
    end

    show do
        panel "Saft Details" do
            attributes_table_for saft do
                row :id
                row :number
                row :title_id
                row :short
                row :description
                row :colour
                row :cover_alt
                row :created_at
                row :updated_at
            end
        end
        active_admin_comments
    end
end

仅供上下文:SAFT是一本杂志,包含文本,图像,作者等。所有其他资源在Admin中运行良好。只有show page的SAFT不起作用。它可能是什么?

1 个答案:

答案 0 :(得分:0)

您的日志条目表示关键字未响应empty?中的Pages::Show#default_titledefault_title来电display_name,您是否覆盖了display_name_methods?在这种情况下,您可以删除:title

config/initializers/active_admin

config.display_name_methods = [ :display_name,
                                  :full_name,
                                  :name,
                                  :username,
                                  :login,
                                  :email,
                                  :to_s ]

在这种情况下,您也可以尝试更明确地设置标题,例如。

  show title: :short do ...

我注意到你使用的是Rails和ActiveAdmin的旧版本,我希望你会考虑upgrading