It may seem I don't google enough before posting here, but that's not the case:)

I refactored my validations according to the Tech. Arch.'s sample app [1] and rescue errors if any in my controller and then I've made a custom "flash" like notification in my form rendered in the view.

Now I have the desired behavior: if there are any errors, the review form isn't created and the user gets the list of error's and a chance to correct their input before submitting again.



On 11. 10. 2014 09:09, Sebastjan Hribar wrote:
Hi guys,

I need help with validations, or to be more exact, what happens after validations fail.

Here are my AR validations in the model:

  class Reviewform < Base
    validates :project_number, :subproject_number, :translator,
              :reviewer, :no_tus, :allocated_time,
              :time_spent, presence: true

These work and produce standard error output in the browser, which is ugly for the end user. I'm struggling with making a nicer error message.

Here's my controller:

  class FormNew
    def get
      @reviewform =
      render :new

    def post
      @reviewform = Reviewform.create(common_attributes)

      if @reviewform.errors
        render :error



I check if there are any errors for the @reviewform and then I want to render the error view. However, it doesn't work. I get:

Mab::Mixin::Error at /form/new
Tags can only be written within a `mab { }`-block

If I change render with redirect Index it works.

What I'd need to do is if the above validations pass, then create the form, otherwise stay on the page and let the user now there are errors. Like the flash in rails. Can it be done in some way?

Thank you.

Camping-list mailing list

Reply via email to