在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
错误,因为它们并未真正定义。我是否误解了控制器操作应该如何编辑?
答案 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