Search code examples
ruby-on-railsruby-on-rails-5

rails model validation error on view does not render properly


i am using a status radio_button field on form, and when i add validate :status, presence: true error message on form doesn't render properly it makes form view weired. Is there any solution i can render status error better?

i have added screenshot look at status field it was inline but after error i get status field in open upon other.

enter image description here

<div class="row">
  <div class="field columns large-6">
    <%= form.label :status %>
    <span>
    <%= form.radio_button :status, "1"  %>
    <%= form.label :completed %>
    </span>
    <span>
    <%= form.radio_button :status, "0"  %>
    <%= form.label :inprogess %>
    </span>
    <span>
    <%= form.radio_button :status, "2"  %>
    <%= form.label :yet_to_start %>
    </span>
  </div>
  <div class="field columns large-6"></div>
</div>

Solution

  • Try this, add the following piece of code to your application.rb file

    config.action_view.field_error_proc = Proc.new { |html_tag, instance| html_tag }
    

    or you can try making the fields inline by adding this css

    .fields_with_error{ display: inline }
    

    It will stop wrapping fields with errors with divs and that might solve your problem. Worth giving a try.