# Instance variable crossing models/controllers

**URL:** <https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167>\
**Category:** Rails\
**Created:** [February 1, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167 "2007-02-01T23:08:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 1, 2007, 11:08pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/1 "2007-02-01T23:08:19Z")

</div>

I am playing around with tabnav plugin  
[http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app](http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app)

The methodology of this plugin has a separate model and controller for  
each level of tabs (and I am planning on nesting the tabs). This makes  
it impossible to use a standard instance variable - for example…

clients\_tabnav model sets the tabs in this fashion…  
class ClientsTabnav \< Tabnav::Base

```
include Reloadable;

```

add\_tab do  
named ‘General Info’  
links\_to :controller =\> ‘clients’, :action =\> ‘edit\_general\_info’  
‘edit\_general\_info’  
end

add\_tab do  
named ‘Personal Info’  
links\_to :controller =\> ‘clients’, :action =\> ‘edit\_personal\_info’  
‘edit\_personal\_info’  
end

and if I were to add ':id =\> @client.id to the links\_to line, @client.id  
means nothing to this controller but it obviously works in the same view  
that is rendered from one of those ‘actions’ above. I can push the value  
of @client.id into the session hash but I can see that is going to get  
ugly real quick so I’m wondering if there is a way I can link the  
ClientsTabnav Class into the Clients Class so that the @client instance  
variable works?

–  
Craig W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 1, 2007, 11:23pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/2 "2007-02-01T23:23:13Z")

</div>

Craig W. wrote:

> I am playing around with tabnav plugin  
> [http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app](http://blog.seesaw.it/articles/2006/07/23/the-easiest-way-to-add-tabbed-navigation-to-your-rails-app)
> 
> The methodology of this plugin has a separate model and controller for  
> each level of tabs (and I am planning on nesting the tabs). This makes  
> it impossible to use a standard instance variable - for example…
> 
> clients\_tabnav model sets the tabs in this fashion…  
> class ClientsTabnav \< Tabnav::Base
> 
> ```
> include Reloadable;
> 
> ```
> 
> add\_tab do  
> named ‘General Info’  
> links\_to :controller =\> ‘clients’, :action =\> ‘edit\_general\_info’  
> ‘edit\_general\_info’  
> end
> 
> add\_tab do  
> named ‘Personal Info’  
> links\_to :controller =\> ‘clients’, :action =\> ‘edit\_personal\_info’  
> ‘edit\_personal\_info’  
> end
> 
> and if I were to add ':id =\> @client.id to the links\_to line, @client.id  
> means nothing to this controller but it obviously works in the same view

I looked at

[http://blog.seesaw.it/articles/2007/02/01/tabnav-for-rails-1-2](http://blog.seesaw.it/articles/2007/02/01/tabnav-for-rails-1-2)

for an update to TabNav.

I found them mentioning

"A sample of the new code you can write is:

class PostsTabnav \< Tabnav::Base  
add\_tab do  
named ‘Posts list’  
links\_to proc { hash\_for\_posts\_path }  
end

```
add_tab do
  named 'New post'
  links_to proc { hash_for_new_post_path }
end

add_tab do
  named proc{ "Show: " + @post.title }
  links_to proc{ hash_for_post_path(:id => @post.id) }
  show_if proc{ !@post.nil? && !@post.id.nil? }
end

```

:  
:"

Would that help?

Stephan

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 1, 2007, 11:50pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/3 "2007-02-01T23:50:26Z")

</div>

On Thu, 2007-02-01 at 23:23 +0100, Stephan W. wrote:

> > ```
> > links_to :controller => 'clients', :action => 'edit_personal_info'
> > 
> > ```
> 
> for an update to TabNav.  
> end  
> end  
> :  
> :"
> 
> Would that help?

* * *

I don’t recognize ‘proc’ as anything meaningful - Is it a ruby function?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 2, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/4 "2007-02-02T22:14:25Z")

</div>

On Thu, 2007-02-01 at 23:23 +0100, Stephan W. wrote:

> > ```
> > links_to :controller => 'clients', :action => 'edit_personal_info'
> > 
> > ```
> 
> for an update to TabNav.  
> end  
> end  
> :  
> :"
> 
> Would that help?

* * *

OK - I think I got it but I still don’t understand what ‘proc’ actually  
is and that example wasn’t helpful to me but they have a sample app  
noted on their web site (titled lousy sample app) that used a variation  
of the code using double braces {{ }} and that works - not that I  
understand why but sometimes you have to appreciate luck and not  
question it too much.

Thus a resulting code looks like this…

```
links_to proc{{ :controller => 'clients',
                :action => 'edit_insurance_info',
                :id => @client.id }}

```

Single braces - no workee

Thanks

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 2, 2007, 11:18pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/5 "2007-02-02T23:18:33Z")

</div>

On Fri, 2007-02-02 at 22:22 +0100, Stephan W. wrote:

> > > Would that help?  
> > > links\_to proc{{ :controller =\> ‘clients’,  
> > > Think function-pointer.
> 
> The outer braces define a block, the inner braces a hash.

* * *

To paraphrase PeeWee Herman…

I meant to know that 😉

Thanks - I actually understand that now that you splained it to me.

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [February 2, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/instance-variable-crossing-models-controllers/84167/6 "2007-02-02T22:22:13Z")

</div>

Craig W. wrote:

> On Thu, 2007-02-01 at 23:23 +0100, Stephan W. wrote:
> 
> > > ```
> > > links_to :controller => 'clients', :action => 'edit_personal_info'
> > > 
> > > ```
> > 
> > for an update to TabNav.  
> > end  
> > end  
> > :  
> > :"
> > 
> > Would that help?
> 
> * * *
> 
> OK - I think I got it but I still don’t understand what ‘proc’ actually  
> is and that example wasn’t helpful to me but they have a sample app  
> noted on their web site (titled lousy sample app) that used a variation  
> of the code using double braces {{ }} and that works - not that I  
> understand why but sometimes you have to appreciate luck and not  
> question it too much.
> 
> Thus a resulting code looks like this…
> 
> ```
> links_to proc{{ :controller => 'clients',
> :action => 'edit_insurance_info',
> :id => @client.id }}
> 
> ```
> 
> Single braces - no workee

See

[http://www.rubycentral.com/ref/ref\_c\_proc.html](http://www.rubycentral.com/ref/ref_c_proc.html)

Think function-pointer.

The outer braces define a block, the inner braces a hash.

Stephan

> Thanks
> 
> Craig
