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.
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.
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs