yhirano55/approval

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

Opened this issue · 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