tags:

views:

65

answers:

2

Hello, while learning Rails, I keep hearing Local vs Instance but I can't find a definition of the two & the differences. And I'd like to avoid making assumptions.

What are the two and how are they different?

Thanks

+3  A: 

Hi, The main difference between local and instance variable is that local variable is only available in controller, where as instance variable is available in corresponding views also. The controller and views do not share local variables.

Thanks, Anubhaw

Anubhaw
Thanks, can you show a code sample of how they differ?
AnApprentice
Example, @name = "Ruby_rails" is an instance variable and name = "Ruby_rails" is an local variable. Thanks......
Anubhaw
+2  A: 

Read this chapter on Variables in Ruby.

joschi