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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:08:07+00:00 2026-05-14T03:08:07+00:00

So, I’d like for a user to see an error message if he submits

  • 0

So, I’d like for a user to see an error message if he submits a comment and the :name is blank (typical error message, don’t need help with that). However, I’d then like to allow the user to skip that validation once he’s been notified that “we like all comments to have a name.” So, he submits the comment once, sees the notification, then can submit the form again unchanged if he really doesn’t want to add a name, and the validates_presences_of :name is skipped.

But, I’m not sure how to go about doing this. I thought about checking to see where the request is coming from, but after a create, errors are handed off to the “new” action, which is the same as actual “new” comments.

I then thought about checking to see if flash[errors] were present, but that won’t work because there are other validations a comment has to pass.

Finally, I thought about trying a

validates_presences_of :name, :unless
=> :notified

but wasn’t sure how to define notified. I honestly hate asking such an open ended question, but wasn’t sure where to get started. So, is there a way to just check a certain validation once?

Edit: here’s my controller

@comments = params[:comments].values.collect{ |comment| current_user.comments.create(comment) }.reject { |p| p.errors.empty? }

and my view:

<% @comments.each_with_index do |comment, index| %>
   <% fields_for "comments[#{index}]", comment do |f| %>
      <%= render :partial => 'form', :locals => { :f => f } %>
   <% end %>
<% end %>

(the stuff in the ‘form’ partial is just the basic f.label, f.text_area stuff)

I’m thinking the problem is really in my view, since it handles an array of comments. Should the notified hidden field be defined in the ‘form’ partial, or in this “new” view? My thinking is that each iteration of the partial doesn’t need a notified hidden_field, but only the overall form itself. But then again I don’t know.

  • 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-14T03:08:08+00:00Added an answer on May 14, 2026 at 3:08 am

    Your solution should work fine. Just add attr_accessor :notified to the model, and add a hidden field for it in the form: form.hidden_field :notified. Then, in the controller action, if validations fail, set @comment.notified = true before re-displaying the view.

    Edit: Yeah, with multiple comments it is probably easier to just do

    @notified = true
    

    in the controller else statement, and then add

    <%= f.hidden_field :notified, :value => @notified %>
    

    to the form partial. Then, each comment will have notified set to true and will skip that validation.

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

Sidebar

Related Questions

No related questions found

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.