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

  • Home
  • SEARCH
  • 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 9215693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:15:38+00:00 2026-06-18T02:15:38+00:00

I am working on basic blog engine and i have applied validations on comments

  • 0

I am working on basic blog engine and i have applied validations on comments but when i do a submit it doesn’t show errors, instead it shows ActiveRecord::RecordInvalid by rails which is default.

my comments controller is

def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(params[:comment])
redirect_to @post
end

my posts/show view is as below which is working fine for commenting

 <%= form_for [@post, Comment.new] do |f| %>
<p class="comment-notes">Your email address will not be published. Required fields are marked <span class="required">*</span></p>
<p>
<b><%= f.label :name, "Name *   " %></b><%= f.text_field :name %><br /></p>
<p>
<b><%= f.label :body, "Comment" %></b><%= f.text_area :comment, :cols => 60, :rows => 5 %>
</p>
<p>
  <%= f.submit "Post Comment" %>
</p>

can anybody help me to show validation errors on the same posts/show view?

thanks in advance

  • 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-06-18T02:15:39+00:00Added an answer on June 18, 2026 at 2:15 am

    replace

    @comment = @post.comments.create!(params[:comment])
    redirect_to @post
    

    with

    @comment = @post.comments.create(params[:comment])
    if @comment.errors.any?
      render "posts/show"
    else
      redirect_to @post
    end
    

    unlike create, create! will raise error if validations fail

    in posts/show

    <%= form_for [@post, Comment.new] do |f| %>
      <% if @comment && @comment.errors.any? %>
        <% @comment.errors.full_messages.each do |msg| %>
         <li><%= msg %></li>
        <% end %>
      <% end %>
       ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic server working but I want to be able to press
I'm working on a basic blog in Express.js. Say I have route structure like
I'm working on a basic search for my blog, and the basic functionality is
I have a service, as follows: The most basic (working) CherryPy 3.1 Windows service
I have a basic RSS reader that displays the list of Blog posts in
I have been working on a WP7 app, it's image gallery app, with basic
I am new to Silverlight RIA services and I have a basic working prototype
I have started to build a blog engine which is totally unprofesional and meant
I have an MVC 3 site that is working and currently quite basic. There
I have a small, basic working example of using WCF to get two applications

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.