activeadmin自定义呈现,如果 [英] activeadmin custom render if

查看:90
本文介绍了activeadmin自定义呈现,如果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的下面的代码

ActiveAdmin.register Question do
  belongs_to :topic, :optional => true

  controller do
    def index
      @topic = Topic.find_by_id params[:topic_id]
      if @topic
        @questions = @topic.questions
        render 'settings/questions/_by_admin', :layout => 'active_admin'
        return
      end
    end
  end
end

抛出

 NoMethodError in Admin/questions#index

显示


/home/amol/.rvm/ gems/ruby-1.9.2-p290@xxx/gems/activeadmin-0.5.0/app/views/layouts/active_admin.html.arb
其中第1行出现:

/home/amol/.rvm/gems/ruby-1.9.2-p290@xxx/gems/activeadmin-0.5.0/app/views/layouts/active_admin.html.arb where line #1 raised:

未定义方法'base':NilClass

undefined method `base' for nil:NilClass

提取的源代码(#1行附近):

Extracted source (around line #1):

1: insert_tag view_factory.layout

有什么想法吗?这里发生了什么事。
堆栈跟踪未指向我的任何书面代码文件。

any idea? whats happening here. Stack trace is not pointing to any of my written code file.

我想在这里显示的是如果存在@topic,那么我想渲染我的视图否则为默认值。

What I want here is, if @topic is present then I want to render my view else the default one.

推荐答案

我在这种情况下正在调用 super 作为控制器操作的最后一行。

I have this scenario working calling to super as the last line in the controller action.

Super会为您呈现默认视图。

Super will render the default view for you.

这篇关于activeadmin自定义呈现,如果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆