Rahul
Rahul

Reputation: 47086

Rails: How can an instance variable declared in a controller accessible in a view?

Ruby instance variables are accessible to a single object. But in rails, if I declare an instance variable in a controller, it is still accessible in the views. What is the architecture behind this?

Upvotes: 2

Views: 368

Answers (1)

gerky
gerky

Reputation: 6417

Well, your controller calls render which renders your templates. So, the template code is being run within the scope of the controller instance. Therefore, you can use any instance variables declared.

Upvotes: 7

Related Questions