# AJAX tabs cannot pass instance variable to partial

**URL:** <https://www.ruby-forum.com/t/ajax-tabs-cannot-pass-instance-variable-to-partial/146873>\
**Category:** Rails\
**Created:** [August 26, 2008, 11:14am UTC](https://www.ruby-forum.com/t/ajax-tabs-cannot-pass-instance-variable-to-partial/146873 "2008-08-26T11:14:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [August 26, 2008, 11:14am UTC](https://www.ruby-forum.com/t/ajax-tabs-cannot-pass-instance-variable-to-partial/146873/1 "2008-08-26T11:14:42Z")

</div>

I have been trying to understand what Flinn said in  
[http://www.actsasflinn.com/Ajax\_Tabs/index.html#](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==‘ ![Wait]() Loading…’) {  
reloadPane(pane, src);  
}  
}

function reloadPane(pane, src) {  
new Ajax.Updater(pane, src, {asynchronous:1, evalScripts:true,  
onLoading:function(request){pane.innerHTML=‘ ![Wait]() Loading…’}})  
}

{{test.js.rjs}}

page.replace\_html(“ss”, :partial =\> “test”, :object =\> @test)

---

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [August 26, 2008, 11:22am UTC](https://www.ruby-forum.com/t/ajax-tabs-cannot-pass-instance-variable-to-partial/146873/2 "2008-08-26T11:22:20Z")

</div>

On 26 Aug 2008, at 10:14, tyliong wrote:

> I have been trying to understand what Flinn said in  
> [http://www.actsasflinn.com/Ajax\_Tabs/index.html#](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 ###.

Are you expecting the value of @test at the point that main.html.erb  
to be preserved until when your ajax request is handled ?

Fred

---

<div class="post-metadata">

**Author:** ![tyliong](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e9a140/32.png) [@tyliong](https://www.ruby-forum.com/u/tyliong)\
**Post date:** [August 26, 2008, 11:38am UTC](https://www.ruby-forum.com/t/ajax-tabs-cannot-pass-instance-variable-to-partial/146873/3 "2008-08-26T11:38:11Z")

</div>

no i got desperate and was just trying to any tactic i knew to get the  
instance to the partial. i am trying to push the value from the  
controller to the partial. basically the @test = 3.

btw if u guys know of an easier ajax tab method please tell me as well

On Aug 26, 5:21 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
