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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:37:21+00:00 2026-05-20T01:37:21+00:00

I have an Entry model and a Photo model and for each photo, users

  • 0

I have an Entry model and a Photo model and for each photo, users can submit an “entry” — just some text about the photo. On the show page for each photo, I render the full form for the entry. In my entry.rb file, I have the following to count the words of the entry:

validate :count_words

def count_words
  body_size = body.to_s.scan(/[\w-]+/).size
  unless body_size < 300
      errors.add(:entry, "Your entry is too long")
  end
end

When I test an entry that is more than 300 words, the save fails and my controller redirects back to the page they were one. Two problems. First error messages aren’t showing up when the controller redirects. I have this rendered w/ the form (it was generated by scaffold).

  <% if @entry.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@entry.errors.count, "error") %> prohibited this entry from being saved:</h2>

      <ul>
      <% @entry.errors.full_messages.each do |msg| %>
        <li><%= msg %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

This is the controller action, where I suspect the problem lies:

  def create
    @entry = Entry.new(params[:entry])

    respond_to do |format|
      if @entry.save
        format.html { redirect_to(@entry, :notice => 'Your entry was submitted.') }
      else
        format.html { redirect_to :back } 
      end
    end
  end

I’m not quite sure where the problem is. I plan to implement some javascript on the form to validate before the submission anyway, but I want this as a back up. Can someone tell me what I’m doing wrong?

  • 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-20T01:37:22+00:00Added an answer on May 20, 2026 at 1:37 am

    Typically you’d want to have your else statement do a format.html { render :edit } instead of redirect :back.

    When you redirect, the errors don’t persist (as they’re not saved to the database or session).

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

Sidebar

Related Questions

can anybody gimme any help about how to overwrite a model entry. i have
I have a Entry model which has a Pushes field and I want each
Using the following related models (one blog entry can have multiple revisions): class BlogEntryRevision(models.Model):
I have an Entry model which has many Tag s. Tag s are added
I have an entry.rb model and I'm trying to make a semi-complicated validation. I
I have a such model named Foo: class Foo(models.Model): name = models.CharField() entry =
I have the following entry in a properties file: some.key = \n [1:Some value]
I have a cron entry that runs a script at a certain time each
I have and old django site (0.97-pre-SVN-7457) and I'm about to make some changes
Consider I have defined the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model):

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.