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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:15:21+00:00 2026-05-14T04:15:21+00:00

I have a static_controller that is in charge of all the static pages in

  • 0

I have a static_controller that is in charge of all the static pages in the site and works as follows in routes.rb:

map.connect ':id', :controller => 'static', :action => 'show'

I have a static page called about that among other information, has a contact form.
I currently have a contacts_controller that is in charge of inserting the contact information to the database.
Inside my routes.rb file, I have:

map.resources :contacts

My contact form (simplified) looks like this:

<% form_for @contact do |f| %>
    <p class="errors"><%= f.error_messages %></p>  

    <p>
        <%= f.label :first_name %>
        <%= f.text_field :first_name %>
    </p>


    <p class="buttons"><%= f.submit %></p>
<% end %>

Which in turn submits to the create action of my contacts_controller.
My create action looks like this:

def create
    @contact = Contact.new(params[:contact])
    if @contact.save
      flash[:notice] = "Email delivered successfully."
    end
    redirect_to "about"
end

The problem is, is the that when I redirect back to my about page the error_messages for the form get lost (since the error_messages for the form only exist for one request, and that request ends upon redirect).
How would I go about preserving the error_messages and still linking the users back to the about static url?
Would a session/flash be sufficient (if so, what code would I use to pass error messages) or am I going about this whole thing wrong?

Thanks!

  • 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-14T04:15:21+00:00Added an answer on May 14, 2026 at 4:15 am

    I think what might be going on is you need to render rather than redirect.
    Redirect terminates the request, and tells the client to make a new request to a different address. That will lose your errors.
    If your save attempt fails your want to complete the request by rendering the action again with the errors shown.

    def create
    @contact = Contact.new(params[:contact])
    if @contact.save
      flash[:notice] = "Email delivered successfully."
      redirect_to @contact #make a new request for the address of the new record or some other address if you want
    else
      render :action => "new" #complete the request by rendering the new action with the @contact variable that was just created (including the @errors).
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Rails application that uses a static_pages controller to render static pages
I have @Controller @RequestMapping(value=core/*) public class CoreController { public static String exceptionOccurredView = /core/exceptionOccurred;
Suppose I have static ip in a subnet that has DHCP server. If i
I have a static class that I use as my Data Utils for my
We're building a site that will have very minimal code, it's mostly just going
I have a controller that handles file uploads. Ultimately I would like to be
I have a custom view controller that has a view on the bottom half.
I have a controller / action in an ASP.NET MVC3 app. It handles the
I have a page that i want to remain static with two divs that
I have a method in my controller that handles generic page requests, meant for

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.