如何传递验证错误ActiveAdmin

时间:2016-12-08 15:14:59

标签: ruby-on-rails activeadmin

我有一个自定义控制器(我将其用作问题补丁ActiveAdmin not saving has_many nested object

我需要解决的问题是验证错误并保留表单数据。在我执行自定义控制器之前,错误会在输入字段下方弹出,如此

Screnshot

但现在他们没有出现。请帮忙!谢谢:))

ActiveAdmin.register

controller do
    def create
        @section = AbqCouncilors::Councilor.create!(permitted_params[:abq_councilors_councilor].as_json)
        redirect_to admin_abq_councilor_path, notice: "Councilor was successfully created!"         
    end
end

1 个答案:

答案 0 :(得分:1)

我让它与下面的改变一起工作。 重要必须有@resource作为实例变量。不适用于任何其他

controller do
    def create
        @resource = AbqCouncilors::Councilor.new(permitted_params[:abq_councilors_councilor].as_json)
        if @resource.save
            flash[:notice] = "Councilor was successfully created!"
            redirect_to admin_abq_councilor_path(@resource.id)
        else
            flash[:error] = "Your form is missing or has incomplete fields. Please review your entry below."
            render action: 'new'
        end
    end
end