0

我在我的活动管理界面中添加了以下内容:

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

这会引发以下错误:

:Arbre::HTML::Article 的未定义方法“已批准”

我认为正在发生的是 Active Admin 认为我正在传递文章标签,而不是文章类?

有谁知道解决这个问题?也许混叠?

谢谢!

类文章 < ActiveRecord::Base

attr_accessible :正文

# 关系:belongs_to:articleable,多态:true,:counter_cache => true has_many:comments,as::commentable,order:'created_at DESC',依赖::destroy

# 验证 validates_presence_of :body validates_length_of :body, 最大值:15000

结尾

4

2 回答 2

1

找到了解决方法

当你将你的类命名为“文章”时有一些可疑的东西,ActiveAdmin 在呈现为<article>HTML 标记时与之相关- 问题当然出在控制器的某个地方,因为这是生成文章对象的地方

所以,我覆盖了控制器

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

享受

于 2013-07-09T07:28:50.787 回答
0

假设您在“显示”块中遇到问题,您可以将显示块更改为以下内容:

show do |object|
end

然后你可以调用 object.some_method 而不会发生冲突。这样您就不需要覆盖控制器。

于 2016-01-22T15:11:17.210 回答