dimanche 25 février 2018

Active Admin Show Page for one model is not working

I am integrating Active Admin into a Ruby on Rails app. I registered all my models and already set up index, filter and show for all the models. Everything is working, but for one model the admin/show page is not running.

When calling the show page from the admin/index page, I get:

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

The relative entry in my log file is:

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)

The rails model is:

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

The ActiveAdmin resource is:

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

Just for context: SAFT is a magazine, with texts, images, authors, etc. All the other resources are working well in Admin. Only the show page of SAFT is not working. What could it be?

Aucun commentaire:

Enregistrer un commentaire