7stud -- wrote: > Doug Jolley wrote: > Perhaps a more basic question is: why is the template able to access the > private variables in the controller at all? In other words, if you > define a ruby class like this:
Rails does some magic to make that happen. Here is a blog post that explains the basics of how this happens: http://www.neeraj.name/blog/articles/719-how-controller-and-view-share-instance-variables > then all the other methods in class A can access @var, but an object of > class B cannot access @var. I think a template is over in class B > somewhere. Yes, you are correct about this in the general case, but as you can see above Rails performs some additional work to simplify template development by coping ivars from the controller into the views. >> (2) Is there some way >> (other than using a global variable) that I can set a variable in a >> controller and have its value available to all templates associated >> with that controller? >> > > Sessions? I would think avoiding global variable would be a very smart thing to do. Session variables might be what you want. It really all depends on what you're trying to do. Generally speaking if you find yourself fighting against Rails you've probably got a design problem. Of course, there's exceptions to every rule. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---