I have been trying to understand what Flinn said in
http://www.actsasflinn.com/Ajax_Tabs/index.html#
{{Problem }}
I don’t understand how to pass the instance variable to the partial.
in the main html “url_for(:action => ‘test’)” does not seem to pass
the instance @test to the partial. output is ###.
{{CODE}}
{{in main html.erb}}
- <%= link_to_function('Vendor', "loadPane($('part_pane'), '" + url_for(:action => 'test') + "'),tabselect($('vendor_tab')); paneselect($('vendor_pane'))") %>
- <%= render :partial => 'test', :object => @groceries %>
{{CONTROLLER}}
def test
@test = "3"
respond_to do |format|
format.html
format.js {
render :update do |page|
page.replace_html 'ss', :partial => 'test'
end
}
format.xml { render :xml => @test.to_xml }
end
end
{{partial}}
test is <%= @test%>
{{JS library}}
function tabselect(tab) {
var tablist = $(‘tabcontrol1’).getElementsByTagName(‘li’);
var nodes = $A(tablist);
var lClassType = tab.className.substring(0,
tab.className.indexOf(‘-’) );
nodes.each(function(node){
if (node.id == tab.id) {
tab.className=lClassType+‘-selected’;
} else {
node.className=lClassType+‘-unselected’;
};
});
}
function paneselect(pane) {
var panelist = $(‘panecontrol1’).getElementsByTagName(‘li’);
var nodes = $A(panelist);
nodes.each(function(node){
if (node.id == pane.id) {
pane.className=‘pane-selected’;
} else {
node.className=‘pane-unselected’;
};
});
}
function loadPane(pane, src) {
if (pane.innerHTML==‘’ || pane.innerHTML==‘ Loading…’) {
reloadPane(pane, src);
}
}
function reloadPane(pane, src) {
new Ajax.Updater(pane, src, {asynchronous:1, evalScripts:true,
onLoading:function(request){pane.innerHTML=‘ Loading…’}})
}
{{test.js.rjs}}
page.replace_html(“ss”, :partial => “test”, :object => @test)