0
votes

I have made the following addition to my active admin interface:

action_item :only => :show do
   link_to('Approve this article', approve_admin_article_path(article)) if article.approved.nil?
end

member_action :approve, :method => :get do
  # do approval
  redirect_to :action => :show, :notice => "Approved!"
end

This throws the following error:

undefined method `approved' for :Arbre::HTML::Article

What I think is happening is Active Admin thinks I'm passing an article tag in, not an article class?

Does anyone know of a work around for this? perhaps aliasing?

Thanks!

class Article < ActiveRecord::Base

attr_accessible :body

# Relations: belongs_to :articleable, polymorphic: true, :counter_cache => true has_many :comments, as: :commentable, order: 'created_at DESC', dependent: :destroy

# Validations validates_presence_of :body validates_length_of :body, maximum: 15000

end

2
can you add the article model? - James
Done, hope this helps. :) - Rtype

2 Answers

1
votes

Found a workaround

There is something fishy when you name your class as 'Article', ActiveAdmin relate to it when rendering as <article> HTML tag - The problem is somewhere in the controller of course because this is where the article object is being generated

So, I override the controller

ActiveAdmin.register Article do

  controller do
    def show
      # grabbing my desired Article and not the <article> tag into some global variable
      @@myarticle = Article.find(params[:id])
    end
  end

  sidebar :article_details , :only => :show do
    ul do
      # using the @@myarticle which I know should be initialized
      # (you can put .nil? checking here if you want)
      li link_to 'Article Images (' + @@myarticle.images.count.to_s + ')' , admin_article_article_images_path(@@myarticle)
      li link_to 'Article Clips ('+@@myarticle.clips.count.to_s + ')' , admin_article_article_clips_path(@@myarticle)        
    end
  end
end

Enjoy

0
votes

Assuming you're having the issue in the 'show' block, you could change the show block to the following:

show do |object|
end

Then you can call object.some_method without the clash. This way you don't need to override the controller.