views:

26

answers:

1

I am trying to use link_to_remote with :with parameter so I can pass my parameters but I am using jrails and it seems it doesn't work. I use it another spot with jrails and prototype and it worked fine. Here is my code in jrails where I don't use prototype:

<%= link_to_remote render(:partial => "back_button_text"),
   {:url => { :controller=> "content", :action => "ajax_sec_cat_display", :with => "'location=' + $("#history").html()" },
   :loading => "addSpinner()",
   :complete => "removeSpinner()"},
   :class => "menu_item back"
%>

And here is the jrails and prototype that is working:

<%= link_to_remote( "Google Map Look Up", 
      :url =>{ :action => :google_map}, 
      :with => "'location=' + $('vcompany_locations_attributes_0_address_1').value") 
   %>
A: 

I finally did it with unobstrusive jquery like this:

$(document).ready(function(){

$(".back").live("click", function() {
    var history = $("#history").html();
    $.ajax({
        beforeSend: function(request){addSpinner();}, 
        complete: function(request){removeSpinner()}, 
        data: 'history=' + history, 
        dataType:'script', 
        type:'post', 
        url:'/content/ajax_back_history'
    });
});
return false;

});

So when you click it, it takes the html from the history div and sends it to rails. I can use it in the controller and in the rjs with params[:history].

The only concern is that I don't have the authentication token, and I am wondering if there is something bad about that...

JohnDel