Instance variable crossing models/controllers


#1

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 W. removed_email_address@domain.invalid


#2

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

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?

Stephan


#3

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


#4

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


#5

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 :wink:

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

Craig


#6

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

Think function-pointer.

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

Stephan

Thanks

Craig