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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:30:44+00:00 2026-06-12T22:30:44+00:00

I have a website using unobtrusive ajax. In short, the flow is: remote link

  • 0

I have a website using unobtrusive ajax.

In short, the flow is:

  • remote link
  • Request managed by controller
  • js.erb view sending response back to browser

I want all my js.erb views to execute similar "maintenance activity", like inserting flash messages when needed, updating the url, etc.

How can I make this DRY? Ideally, I would use a partial with the code to be executed every time but I couldn’t find how to do this.

My js.erb file:

$("#challenge_actions").html("<%= escape_javascript(render partial: "challenges/best_practice_button")%>");
$("#flash_messages").html("<div id='flash_notice'><%= escape_javascript(flash[:notice])%></div>");

How can I extract the line with flash_messages and have it automatically included in all my js.erb files?

  • 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-06-12T22:30:46+00:00Added an answer on June 12, 2026 at 10:30 pm

    You can use js layouts , just like html layouts.

    layouts/custom.js.erb

    alert("<%=j flash[:notice] %>");
    <%= yield %>
    

    controllers/your_controller.rb

    def your_action
    
      flash[:notice] = "hello world"
      @hello = "hello world"
    
      respond_to do |format|
        format.js { render layout: "custom" }
      end
    end
    

    your_action.js.erb

    alert("<%= j @hello %>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a website using MVC3 along with the Razor view engine. What
I have a website using ASP with an MS Access DB back-end for storing
I would like to publish a website using msbuild. Since I have a website
I have a website which using active directory authorization on a windows server in
I have developed a website using Razor (Microsoft WebMatrix) and now I want to
I have made a website using( Asp.net, c# ) and its content in English
I have created a website using vbulletin i have installed CMS and BLOG modules
I have created a website using modx evolution v1.0.2. The website that I have
Currently I have create a website using codeigniter. I got a message error every
I have a website that's using forms authentication and membership. A user must have

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.