I have a table and when I mouseover a row I want a pop-up with some additional information for that specific row (called remotely). I can do this easily with something along the lines of... onmouseover="<%= remote_function(:updated => "notediv", :loading => " Element.show(''note'');", :url => {:action => ''get_note'', :id => inventory.id<http://inventory.id>}) -%>" onmouseout="Element.hide(''note'')". Okay, the problem with that is, when someone moves the mouse over several rows and then settles on one row, it loads the data from all those rows, causing a lagged response. I need to abort the remote call in onmouseover. This isn''t a huge problem. I have to remove the :loading part from my helper function and do it myself, but in the end I can do something like this... onmouseover="abortCallandShowDiv(); tempvar = <%remote_function(:update=>''notediv'', :url => {:action => ''get_note'', :id => inventory.id <http://inventory.id>}) -%>" And that works, but now I''m serving twice as much data as I need to. The purist in me really wants to move all this javascript into a single function in an external file. onmouseover would just call one function passing the event and the id as arguments. And I can do this, but I have to hardcode the call to new Ajax.Updater, so it looks something like this... tempvar = new Ajax.Updater(''notediv'', ''/store_room/get_note/'' + id, {asynchronous:true, evalScripts:true}); I just copied the result of remote_function. Anyhow, as you can probably tell this is going to cause a problem if my app is deployed to a subdirectory, say /inventory, then the Ajax.Updater should call ''/inventory/store_room/get_note'' + id, but it won''t. I need that :url magic in my external .js file. Is there a solution to this? _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Julian ''Julik'' Tarkhanov
2005-Oct-11 18:09 UTC
Re: Pushing Javascript Helper to external file.
On 11-okt-2005, at 19:24, Rube wrote:> > I just copied the result of remote_function. Anyhow, as you can > probably tell this is going to cause a problem if my app is > deployed to a subdirectory, say /inventory, then the Ajax.Updater > should call ''/inventory/store_room/get_note'' + id, but it won''t. I > need that :url magic in my external .js file. > > Is there a solution to this?class JavascriptController < ApplicationController before_filter :javascript_header layout nil def index render :text=>''alert("Hello from the controller")'' end def whatever @items_belonging_to_user = Item.all_find_by_owner_id(@user.id) # will render whatever.rhtml where you can put some javascript end private def javascript_header response.env["Content-type"] = "text/javascript" end end -- Julian "Julik" Tarkhanov
On Tuesday 11 October 2005 19:24, Rube wrote:> I just copied the result of remote_function. Anyhow, as you can > probably tell this is going to cause a problem if my app is deployed > to a subdirectory, say /inventory, then the Ajax.Updater should call > ''/inventory/store_room/get_note'' + id, but it won''t. I need that > :url magic in my external .js file.No magic, but two suggestions 1) define a JavaScript variable urlPrefix in your main layout 2) include a config script where you define such a prefix Michael -- Michael Schuerig Most people would rather die than think. mailto:michael-q5aiKMLteq4b1SvskN2V4Q@public.gmane.org In fact, they do. http://www.schuerig.de/michael/ --Bertrand Russell