approval icon indicating copy to clipboard operation
approval copied to clipboard

add a docs example to show how to handle validation errors?

Open jhackett1 opened this issue 4 years ago • 0 comments

when you file a request rather than do a normal save it doesn't seem like model validation errors display in the form.

i handled this with the code below, but i'm not sure it's the best solution or if it's handling all possible errors. would be good to address this in the docs!

    def create
        @service = current_user.organisation.services.build(service_params)
        if @service.valid?
            current_user.request_for_create(@service, reason: "something").save
            redirect_to organisations_path, notice: "Your service has been submitted for review. You'll be emailed when it's approved."
        else
            render "new"
        end
    end

jhackett1 avatar Apr 19 '20 09:04 jhackett1