coolesting
2011-Aug-25 02:39 UTC
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. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Colin Law
2011-Aug-25 06:38 UTC
Re: passing intance variable from controller application_controller.rb to view template
On 25 August 2011 03:39, coolesting <coolesting-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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/ -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
coolesting
2011-Aug-25 07:32 UTC
Re: passing intance variable from controller application_controller.rb to view template
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 Law <clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>> On 25 August 2011 03:39, coolesting <coolesting-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> 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/ > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
7stud --
2011-Aug-25 09:55 UTC
Re: passing intance variable from controller application_controller.rb to view template
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 self.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 -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.