instance variable crossing models/controllers

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

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 White 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 > > 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

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?

Craig White 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 > > 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

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?

Craig White 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

Think function-pointer.

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