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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:08:56+00:00 2026-05-25T11:08:56+00:00

I just updated to Rails 3.1 and a typical ajax form to create a

  • 0

I just updated to Rails 3.1 and a typical ajax form to create a model object is producing the following error on success: ActionView::Template::Error (undefined method gsub' for #<ActionDispatch::Flash::FlashHash:0x00000102b73b78>):

The create action is going well, the data is submitted to the database, but the page does not change and the js doesn’t execute. the js DOES work if there’s an error, producing the error message as expected…. So only the success is producing the error and failing to execute the js.

Here’s my code:

Controller:

def create
  @contact  = Contact.new(params[:contact])
  respond_to do |format|
    if @contact.save
      flash[:notice] = "Welcome!"
      format.html
      format.js
    else
      format.html { render 'pages/home'}
      format.js
    end
  end
end

view form

<div id="contact_notice"></div>
<%= form_for @contact, :remote => true do |f| %>
  <%= f.text_field :email, :id => 'email', 'data-default' => 'Sign up to join the beta!' %><%= f.submit "Submit", :id => 'submit' %>
<% end %>

/views/contacts/create.js.erb

<% if @contact.errors.any? %>

// Create errors
var errors = $('<div class="flash notice"></div>');
<% @contact.errors.full_messages.each do |error| %>
  errors.append('<%= escape_javascript( error ) %>');
<% end %>

// Display errors
$("#contact_notice").html(errors);

<% else %>

// Display success (clearing any errors)
$("#contact_notice").html('<div class="flash notice"><%=escape_javascript(flash.delete(:notice)) %></div>'); 
<% end %>

And here’s the stack trace when a new contact is saved:

Rendered contacts/create.js.erb (0.6ms)
Completed 500 Internal Server Error in 13ms

ActionView::Template::Error (undefined method `gsub' for #<ActionDispatch::Flash::FlashHash:0x000001042b1970>):
12: <% else %>
13: 
14:   // Display success (clearing any errors)
15:   $("#contact_notice").html('<div class="flash notice"><%= escape_javascript(flash.delete(:notice)) %></div>'); 
16: 
17: <% end %>
app/views/contacts/create.js.erb:15:in `_app_views_contacts_create_js_erb__3535867194219445180_2168748520'
app/controllers/contacts_controller.rb:6:in `create'

Let me know if you can see what I’m missing here. Thank a bunch.

  • 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-25T11:08:57+00:00Added an answer on May 25, 2026 at 11:08 am

    Rails has changed the way some things work in 3.1, from what I understand Rails 3.1 is not using Hash for the FlashHash any more and they now are basing it off of Enumerable. Here is an answer that goes into more detail. You should be able to use:

    flash.discard(:notice)
    

    Instead of the old:

    flash.delete(:notice) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just updated my django to 1.4. But I am getting the following error
I've just updated rails to v2.3.6 on my app under a bamboo-ree-1.8.7 stack and
I just updated to Rails 3.2 and I started to get errors like this:
I tried out rails 3, and just started a new project. The following is
I'm just trying to figure out why when I create a new rails application,
I'm on Rails 2.3.5. In a typical user controller create action class UsersController def
I've just updated to Rails 2.3.11. In an earlier version I could write the
I just updated to rails 3.2 and twitter gem 2.0.2 Now when I start
I have just updated my app from Rails 2.3.5 to Rails 3. One of
Okay so I was just starting this rails app and generated my first 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.