Rails 3: “field-with-errors” wrapper changes the page appearance. How to avoid this?

Rails 3: “field-with-errors” wrapper changes the page appearance. How to avoid this?

Add Comment


  • 3 Answer(s)

    Default ActionView::Base.field_error_proc. Its currently defined  within ActionView::Base: 

    @@field_error_proc = Proc.new{ |html_tag, instance|
       "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe
    }
    

    Using class inside config/application.rb:

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

    Answered on January 10, 2019.
    Add Comment

    The div element is a block element. Add style  CSS file to make it inline element:

    .field_with_errors { display: inline; }
    

    Answered on January 10, 2019.
    Add Comment

    Follow this command: 

    ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|
       class_attr_index = html_tag.index 'class="'
     
       if class_attr_index
        html_tag.insert class_attr_index+7, 'error '
       else
        html_tag.insert html_tag.index('>'), ' class="error"'
      end
    end
    

    Answered on January 10, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.