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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:20:41+00:00 2026-05-24T03:20:41+00:00

I’m thinking of implementing something like the following and would like to know a)

  • 0

I’m thinking of implementing something like the following and would like to know a) if it’s possibly a really bad idea for some reason I haven’t thought of, and b) if not – is there an existing gem out there to do it.

Basically, I’d like to be able to queue javascript events from my rails controllers so that on next render all queued events would be triggered and removed from the queue. Sort of like the flash mechanism but for events instead. So e.g.:

in my controller:

def create
  if resource.create 
    add_event('resourceCreated', :id => resource.id)
  end
end

and in my application layout something like:

%javascript
  - @events.each do |e|
    $(document).trigger(#{e.event_name}, #{e.event_data})

Any thoughts?

Edit: This would be useful e.g. when an item is created, the server may redirect to the edit form for said item, or may redirect to the index action for the relevant controller. These pages don’t know that an item was just created. However perhaps I want to do something like close a dialog window if the item was created successfully but leave it open if it was not, or any number of other possible reasons I may need to know about it. Obviously not just relevant for creates, that’s just the example I’m using to illustrate the problem

Edit: Bounty goes to whoever persuades me convincingly one way or the other that this is a good/bad idea or provides a better alternative

  • 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-24T03:20:41+00:00Added an answer on May 24, 2026 at 3:20 am

    I see what you are trying to do, but you need to be careful about keeping things separate.

    What I would do in this situation is create a hash and then #to_json it in your view. Let’s say at the bottom of your action

    controller

    @events = [
       { :type => "item_created", :message => "Woohoo! Item was created"}
    ]
    

    index.html.erb

    <div>Your usual stuff goes here</div>
    <script type="text/javascript" charset="utf-8">
      var events = <%= raw @events.to_json %> // You must make sure it's properly sanitised
    </script>
    

    jQuery

    $.ready(function() { 
       events.each(function () {
          // ... Do what you need to with this
       });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to render a haml file in a javascript response like so:

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.