Hello, I have a custom controller (I'm using it as a patch for issue #4685)
the problem I need to fix is the validation errors and keeping the form data. Before I did the custom controller, the errors would pop up underneath the input field like so
but now they do not show up. Please help! Thanks :)
ActiveAdmin.register
controller do
def create
@section = AbqCouncilors::Councilor.create!(permitted_params[:abq_councilors_councilor].as_json)
redirect_to admin_faq_sections_path, notice: "Section was successfully created!"
end
end
Looks like it should raise an error on validator error or proceed to redirect on a list. You have to write additional logic in create
action method.
@dmitry have an example?
I got it with the below change.
Important Must have @resource
as the instance variable. Would not work with any other
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
Most helpful comment
I got it with the below change.
Important Must have
@resource
as the instance variable. Would not work with any other