activeadmin custom render if

浪尽此生 提交于 2019-12-11 14:10:00

问题


My below code

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

is throwing

 NoMethodError in Admin/questions#index

Showing

/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:

undefined method `base' for nil:NilClass

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.

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


回答1:


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

Super will render the default view for you.



来源:https://stackoverflow.com/questions/13116244/activeadmin-custom-render-if

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!