Passing intance variable from controller application_controller.rb to view template

Hi, guy.

How to pass a variable from application_controller.rb to view template.
Whatever it is what kind of variable. I just want to pass the variable
value
to template.

Thank you.

On 25 August 2011 03:39, coolesting [email protected] wrote:

Hi, guy.

How to pass a variable from application_controller.rb to view template.
Whatever it is what kind of variable. I just want to pass the variable value
to template.

In a method in the controller say
@my_variable = the_value

Call that method from the action being performed and access
@my_variable in the view.


Colin
https://plus.google.com/111605230843729345543/

Thanks Colin,
I solved this problem, if i do as you said , it just works in normal
controller, not in application_controller.rb

I should do like this ,

before_filter :my_var

def my_var
@my_var = ‘a string’
end

So it works in view as normally variable invoked.

2011/8/24 Colin L. [email protected]

coolesting d. wrote in post #1018357:

Hi, guy.

How to pass a variable from application_controller.rb to view template.
Whatever it is what kind of variable. I just want to pass the variable
value
to template.

Thank you.

class Animal
@val = 10

def Animal.val
@val
end

end

class Dog < Animal
def some_action
@val_from_app_controller = Animal.val
puts @val_from_app_controller
end
end

controller = Dog.new
controller.some_action

–output:–
10