I am going to implement something like the following and would like to know: a) if it can be a really bad idea for some reason that I did not think about, and b) if not, is there a real stone for this.
Basically, I would like to be able to queue javascript events from my rails controllers so that at the next rendering all the queues in the queue are started and removed from the queue. Most likely as a flash mechanism, but for events. For example:
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(
Any thoughts?
Edit: That would be useful, for example. when an element is created, the server can redirect to the edit form for the specified element or redirect to the index action for the corresponding controller. These pages do not know that the item has just been created. However, perhaps I want to do something like close the dialog box if the item was created successfully, but leave it open if it isn't, or any number of other possible reasons that I might need to know about. Obviously, this is not just important to create, it is just an example that I use to illustrate the problem.
Edit: The bounty goes to the one who convinces me convincingly, anyway, that this is a good / bad idea or provides a better alternative
source share