Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3425828
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:38:26+00:00 2026-05-18T06:38:26+00:00

How can i display the validation error messages just below the form field rather

  • 0

How can i display the validation error messages just below the form field rather than showing all messages at the top of the page.

My Rails version is Rails 3.0.0

I have a table name category with fields id, title and description.
My model class is

class Category < ActiveRecord::Base
  validates_uniqueness_of :title, :message => "Title already exist"
  validates_presence_of :title, :description => "Cannot be blank"
end

Controller

class CategoriesController < ApplicationController

  def index
  end

  def new
  end

  def create
     @category = Category.new(params[:category])
     @category.created = Time.now
     @category.modified = Time.now
     respond_to do |format|
       if @category.save
         @category_last=Category.last
           format.html { redirect_to :controller => 'categories', :action => 'show', :id => @category_last.id }
       else
          #format.html { redirect_to :controller => 'categories', :action => 'new' } 
        end
     end
  end

  def show
  end

  def edit
  end

end

and View

<div id="newCategory" class='page add'>
    <div class='screenTitle'>New Category</div>
    <div class='form_wrapper'>
        <%= form_tag :action=>'create' %>
            <div class='field_wrapper'>
                <div class='field_label'>
                    Title 
                </div>
                <div class='field_input'>
                    <%= text_area(:category, :description, :class=>'') %>
                </div>
                <div class='clearfix'>&nbsp;</div>
            </div>
            <div class='field_wrapper'>
                <div class='field_label'>
                    Title 
                </div>
                <div class='field_input'>
                    <%= text_field(:category, :title, :class=>'') %>
                </div>
                <div class='clearfix'>&nbsp;</div>
            </div>
            <div class='field_wrapper'>
                <div class='field_submit'>
                    <%= submit_tag "Submit", :type => "submit", :class => "submit" %>
                </div>
                <div class='clearfix'>&nbsp;</div>
            </div>
         </form>
    </div>
    <div class='actions'>
        <ul>
            <li><%= link_to 'List Categoris', root_url+'categories' %></li>
        </ul>
        <div class='clearfix'>&nbsp;</div>
    </div>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T06:38:27+00:00Added an answer on May 18, 2026 at 6:38 am

    I would probably do something like this. Use an empty model in the action :new like this:

    def new
      @category = Category.new
    end
    

    And then use form_for instead of form_tag like this:

    <%= form_for @category, :action=>'create' do |f| %>
      <%= f.text_field(:title, :class=>'') %>
    

    And then in the action :create I would try this:

    if @category.save
      # redirect if you want to
    else
      render :action => :new
    end
    

    That way, if the creation fails for some reason, the controller will render the template for :new but still use the failed @category object in the form_for helper. And you can always access the error messages of a model with @category.errors.on(:title)

    So add the following to the view where you want the error message displayed:

    <%= @category.errors.on(:title) unless @category.errors.on(:title).nil? %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I display both individual error messages and summary for the jQuery plugin?
I'm trying to dynamically create a div to show error messages using jquery. I'm
Even if I offer alternatives to PUT and DELETE (c.f. Low REST), how can
I have a RequiredFieldValidator with Display=Dynamic on my ASP.NET WebForm. I have assigned it
I have been trying to retrieve data via AJAX. I can't seem to be
When I enter 9:00 into the Start control, and 16:00 into Finish; the code
I think I understand the basic concepts of MVC - the Model contains the
I'm unable to see what I may be doing wrong with the following Symfony
I am creating a WPF app using MVVM. The app manages tagged documents, called
I have a class that is bound to GUI elements as follows: <TextBox Style={StaticResource

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.