ActiveAdmin修改现有的控制器操作

时间:2014-09-02 14:52:11

标签: ruby-on-rails ruby variables controller activeadmin

在ActiveAdmin中,我尝试在show视图中编辑实例变量。我尝试使用ActiveAdmin docs的以下代码执行此操作:

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

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

1 个答案:

答案 0 :(得分:0)

尝试使用show block而不是控制器中的show action: 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