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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:04:00+00:00 2026-05-11T07:04:00+00:00

Most of my js.erb files contains something like this at the bottom: $(#flash_message).html(<%= escape_javascript(content_tag(:p,

  • 0

Most of my js.erb files contains something like this at the bottom:

$('#flash_message').html('<%= escape_javascript(content_tag(:p, flash[:note], :class => 'note')) %>'); $('#flash_message').fadeOut(2000); $('#loading').remove(); 

I would like to move these lines into a seperate file and then call that file from each of my js.erb files. Is something like that possible?

Best regards. Asbørn Morell

  • 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. 2026-05-11T07:04:00+00:00Added an answer on May 11, 2026 at 7:04 am

    Yes, you may create an app/views/shared/_flash_messages.js.rjs partial, which you can then render from anywhere (e.g. from other rjs partials.)

    My approach in these kinds of applications has been as follows:

    • for non-AJAX responses that may have a flash:

      • in the layout (e.g. layouts/application.erb), add e.g.:
        render :partial => 'shared/flash_messages.html.erb'
    • for AJAX responses that may also need to display a flash message, I added the following rjs code:

      • in each rjs response (e.g. controller/action.js.rjs), add e.g.:
        render :partial => 'shared/flash_messages.js.rjs'

    Where the two partials do the necessary to render the flash, then call flash.discard(:error) or flash.discard(:notice) as appropriate.

    Sample app/views/shared/flash_messages.html.erb file:

    <% if flash[:error] %> <div id='flash_message' class='error'><%= h(flash[:error]) %></div> <% flash.discard(:error) %> <% elsif flash[:notice] %> <div id='flash_message' class='notice'><%= h(flash[:notice]) %></div> <% flash.discard(:notice) %> <% else %> <div id='flash_message' style='display: none;' /> <% end %> 

    Sample app/views/shared/flash_messages.html.rjs file:

    if !flash[:error].blank?   page['flash_message'].     replace_html(flash[:error]).     removeClassName('notice').     addClassName('error').     show() else   page['flash_message'].     replace_html(flash[:notice]).     removeClassName('error').     addClassName('notice').     show() end 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Until a week ago I was happily coding html.erb files in Notepad++ with syntax
Most of my C/C++ development involves monolithic module files and absolutely no classes whatsoever,
Most of the implementations I find require a hardware instruction to do this. However
I know this is the most common problem in the history of programming but
Most examples I see of Unit tests are simple tests like Assert.That(5, 2 +
Most of the examples I found on the net write this: if(x != nil)
Most OSes use paging for virtual memory. Why is this? Why not use segmentation?
Most web pages are normally parsed and of course I don't see tags like
In my global.css file which is loaded by application.html.erb , I have the following
Most of time we represent concepts which can never be less than 0. 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.