Forum: Ruby on Rails instance variable crossing models/controllers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Craig W. (Guest)
on 2007-02-02 00:08
(Received via mailing list)
I am playing around with tabnav plugin
http://blog.seesaw.it/articles/2006/07/23/the-easi...

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>
Stephan W. (Guest)
on 2007-02-02 00:23
Craig W. wrote:
> I am playing around with tabnav plugin
> 
http://blog.seesaw.it/articles/2006/07/23/the-easi...
>
> 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-f...

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
Craig W. (Guest)
on 2007-02-02 00:50
(Received via mailing list)
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
Craig W. (Guest)
on 2007-02-02 23:14
(Received via mailing list)
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
Stephan W. (Guest)
on 2007-02-02 23:22
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
Craig W. (Guest)
on 2007-02-03 00:18
(Received via mailing list)
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
This topic is locked and can not be replied to.