2014-09-02 67 views
0

在ActiveAdmin中我试图编辑show视图中的实例变量。我曾尝试与每ActiveAdmin docs下面的代码来做到这一点:ActiveAdmin修改现有控制器操作

#admin/job.rb 
ActiveAdmin.register Job do 
... 
controller do 
    def show 
     @job = Job.find(params[:id]) 
     @comment = Comment.new 
     @comments = @job.comments 
    end 
end 
... 

这导致nilClass错误,当我尝试使用这些变量在ActiveAdmin show,因为他们并没有真正定义。我误解了控制器操作应该如何编辑?

+0

随着'@ comments'变量做你想要出现在显示页面上的评论? – nistvan 2014-09-02 15:26:54

+0

是的,他们出现在底部 – sixty4bit 2014-09-02 15:42:26

回答

0

尝试使用show块不是show动作控制器: https://github.com/activeadmin/activeadmin/blob/master/docs/6-show-pages.md#customize-the-show-page

ActiveAdmin.register Job do 
    show do |job| 
    attributes_table do 
     row :attributes_of_job 
    end 
    #you can also reach the comments like this: job.comments 
    active_admin_comments 
    end 
end 
+0

我已经有一个显示块,但我想喂给额外的实例变量。通常我会通过在控制器的show动作中声明实例变量来做到这一点。我以为这是我在OP链接的文档解释如何做,但它不工作 – sixty4bit 2014-09-08 15:49:33

+0

job.comments不工作?您不需要实例变量..您可以通过show block中的作业参考和所有关联的记录到达记录。 – nistvan 2014-09-08 17:19:48