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 9192807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:01:03+00:00 2026-06-17T21:01:03+00:00

In my situation, somehow it doesn’t show validation error message even if there was

  • 0

In my situation, somehow it doesn’t show validation error message even if there was validation error.

For example, I leave these 2 column as empty, and make sure that captcha word is typed in. Then if I try to create new record. It won’t show validation error:(
It comes back to the form but no message.

I’ve been using validation error message all the time in this project , and I never faced this problem.

Anyone can find the problem here?

Validation in Topic model

validates :title,   
    :presence => {:message => "can't be empty" },    
    :uniqueness => {:message => "choose unique title" },    
    :length => { :maximum => 20, :message => "must be less than 20 characters" }

validates :body,   
    :presence => {:message => "can't be empty" },    
    :length => { :maximum => 500, :message => "must be less than 20 characters" }

Form

<%= form_for([@community, @topic]) do |f| %>
.....

    <%= button_tag( :class => "btn btn-primary") do %>
    Create
    <% end %>

<% end %>

topic_controller

before_filter :simple_captcha_check, :only => [:update, :create]

def simple_captcha_check
    if !simple_captcha_valid?
        flash[:error] = 'wrong captcha'
        if request.put?
            @topic.attributes = params[:topic]  
            render :action => :edit
        elsif request.post?     
            @topic = Topic.new params[:topic]
            render :action => :new
        end
    end
end


def create
    @topic = @community.topics.build (params[:topic]) 
    @topic.user_id = current_user.id

    respond_to do |format|
        if @topic.save
            format.html { redirect_to community_topic_path(@community, @topic), notice: 'Created' }
            format.json { render json: [@community, @topic], status: :created, location: @topic }
        else
            format.html { render action: "new" }
            format.json { render json: @topic.errors, status: :unprocessable_entity }
        end
    end
end

routes.rb

resources :communities do
     resources :topics
end

UPDATE:

views/layouts/application.html.erb

.....
<% flash.each do |name, msg| %>
  <div class="alert alert-<%= name == :notice ? "success" : "error" %>">
    <a class="close" data-dismiss="alert">&#215;</a>
    <%= content_tag :div, msg, :id => "flash_#{name}" if msg.is_a?(String) %>
  </div>
<% end %>
.....
  • 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-17T21:01:04+00:00Added an answer on June 17, 2026 at 9:01 pm

    Flash doesnt appear until the next request. So if you were doing a “Redirect” it would appear.

    You are however, doing a render not a redirect. When you render, you return the body of the view itself.

    But no worries, If you want to render a view (which is just fine), use the flash like this –

    flash.now[:error] = 'wrong captcha'
    

    The .now ensures that the flash gets flushed in the view of the render within the same request.

    EDIT:

    The reason your validations dont appear (when captcha fails) is because your before_filter does rendering and stops the create action from even being called. @topic validations only fire at @topic.save in create but since that never gets called (when captcha fails), nothing related to attribute validations appears there.

    Secondly, flash.now[:error] will ensure that flash message doesnt get transferred to the next request since you intend to use in the same request’s response. If however you set flash[:error] and render, then your flash message WILL appear in the same request’s response AND the next request too. This should answer @saurabh’s good question above and solve the mystery?

    FINAL EDIT:
    @MKK had to include an error displaying partial which was missing from the view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Situation: I'm working with Adobe Livecycle ES2 and Flex In our project we show
Situation: My tooltips show up on my page. Opening my fancybox works. Doing the
I'm not entirely sure how I got to this situation but somehow I'm getting
I have an interesting situation, and Google doesn't appear to have any information regarding
I'm not quite sure how this happened, but somehow a completely empty hierarchy of
Situation is simple: I post a plain HTML form with a textarea. Then, in
Situation: 1. Linux TCP server 2 Windows C# client application The server receives messages
Situation: I have an index page which loads pages into it with ajax as
Situation: I often run into this problematic and never know how to solve it.
Situation is simple. I need to wrap text around two inline objects (buttons with

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.