in my ruby on rails application, i have one controller
class HomeController < ApplicationController
def home
puts "name.....#{@name}"
end
def branch
*//HERE HAVE TO GET THE ABOVE FUNCTION VALUE @name*
end
end
What am trying to do, i have to get the @name value in method branch. i
could show the value in function home, but i didn''t get that in
function
branch..i have tried this with global variable, class variable...but no
response....? can i use the other pgm language property like the method
overriding. or inheritance..?
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/PWEx9dbymacJ.
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.
On 19 April 2012 08:38, amvis <vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> in my ruby on rails application, i have one controller > > class HomeController < ApplicationController > > def home > puts "name.....#{@name}" > end > def branch > //HERE HAVE TO GET THE ABOVE FUNCTION VALUE @name > end > > end > > What am trying to do, i have to get the @name value in method branch. i > could show the value in function home, but i didn''t get that in function > branch..i have tried this with global variable, class variable...but no > response....? can i use the other pgm language property like the method > overriding. or inheritance..?That does not make sense, unless you have missed out some of the code. How is the value @name determined in method home? There seems to be no code there setting it up. Colin -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
The best way to do such things is preset them in before_filter
For example:
class HomeController < ApplicationController
before_filter :set_name
def home
puts "name.....#{@name}"
end
def branch
//HERE HAVE TO GET THE ABOVE FUNCTION VALUE @name
# and here your @name variable should be accessible
end
private
def set_name
@name = "foo"
end
end
I think what you have strange issues in your code, because ruby lang
construction give opportunity to do this obviously.
Artem
19.04.2012, 11:31, "Colin Law"
<clanlaw-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>:> On 19 April 2012 08:38, amvis
<vgrkrishnan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>> in my ruby on rails application, i have one controller
>>
>> class HomeController < ApplicationController
>>
>> def home
>> puts "name.....#{@name}"
>> end
>> def branch
>> //HERE HAVE TO GET THE ABOVE FUNCTION VALUE @name
>> end
>>
>> end
>>
>> What am trying to do, i have to get the @name value in method branch.
i
>> could show the value in function home, but i didn''t get that
in function
>> branch..i have tried this with global variable, class variable...but
no
>> response....? can i use the other pgm language property like the
method
>> overriding. or inheritance..?
>
> That does not make sense, unless you have missed out some of the code.
> How is the value @name determined in method home? There seems to be
> no code there setting it up.
>
> Colin
>
> --
> 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@googlegroups.com.
> 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@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.