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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:02:03+00:00 2026-05-29T11:02:03+00:00

I would like to share FlashHash notices more cleanly between plain-old HTTP users and

  • 0

I would like to share FlashHash notices more cleanly between plain-old HTTP users and UJS folks that I’ve been able to contrive. Allow me to show you what I have first:

First, part of the respond_to section of the relevant controller’s #update:

respond_to do |format|
  if @cont.save
    flash[:notice] = 'Continent was successfully updated.'
    format.html { redirect_to edit_continent_url(@cont) }
    format.json { head :ok }
    format.js

and an update.js.erb to match it:

$('#jsflash').html('<%= escape_javascript(render :partial => "application/notices/notice") %>').show();
<% flash.clear %> # clear the flash to avoid displaying on page reloads

Likewise in my application.html.erb there is

<div id="jsflash"></div>
<%= render "application/notice/alert" %>

and app/views/application/notices/_notice.html.erb:

<% unless flash[:notice].blank? %>
  <div class="alert-message info fade in" data-alert="alert">
    <a class="close" href="#">&times;</a>
    <%= content_tag :p, flash[:notice] %>
  </div>
<% end %>

Things I don’t like:

  1. Maybe it’s anal, but I would prefer to not render <div id="jsflash"></div> unless I absolutely have to.
  2. The <% flash.clear %> in the update js exists to clear flash out in case of page reload. However, that’s going to get really tedious and error-prone as each JS view will need to have this but might forget to include it.
  3. The <% flash.clear %>, likewise, it’s a confusion of roles, with the view driving application state.
  4. It seems like there should be some facility for this already. Have I overlooked something?
  • 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-29T11:02:04+00:00Added an answer on May 29, 2026 at 11:02 am
    1. To avoid rendering <div id="jsflash"></div> when its not needed you will want to wrap the flash block in an if statement. You could put something like this in your Application.rb

    .

     <% if flash.present? %>
       //Call your Render Flash Here
     <% end %>
    

    2.3.4. I’ve never had to use flash.clear in the dozens of flash applications I have made. You also seem to have some unneeded duplication here with your flash calls.

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

Sidebar

Related Questions

I have some content files that I would like to share between a number
I would like to share a template between AJAX and regular HTTP calls, the
I have some common code that I would like to share between pages and
I have a numpy array that I would like to share between a bunch
I would like to share 2 folders of content ('stylesheets' and 'graphics') between multiple
Problem: I would like to share code between multiple assemblies. This shared code will
My problem is: I have 3 procs that would like to share config loaded
Helllo, I would like to share small amounts of data (< 1K) between python
I would like to share an object between various instances of objects of the
I have a bunch of aliases that I would like to share with co-workers

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.