Hi,
Can someone tell me why the following isn''t setting an instance
variable?
Perhaps they can''t be set/used in helpers? I have a revision_info
method in
ApplicationHelper that returns the current SVN revision number (used for
debugging info in the footer):
module ApplicationHelper
def revision_info
logger.info("In revision_info(); rev=#{@rev}") # @rev is always
nil
if (@rev ||= (capistrano_revision_info || svn_revision_info)).blank?
return nil
else
return ''Revision '' + @rev
end
end
end
# capistrano_revision_info returns the revision number from the REVISION
file
# capistrano_revision_info returns the revision number from `svn info --xml`
Thanks in advance for any replies.
Cheers,
Lee
--~--~---------~--~----~------------~-------~--~----~
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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org
2009-Mar-20 18:30 UTC
Re: Instance variables in helpers?
On 20 Mar., 18:36, Lee D''oéjgi <leedoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Can someone tell me why the following isn''t setting an instance variable? > Perhaps they can''t be set/used in helpers? I have a revision_info method in > ApplicationHelper that returns the current SVN revision number (used for > debugging info in the footer): > > module ApplicationHelper > def revision_info > logger.info("In revision_info(); rev=#{@rev}") # @rev is always nil > if (@rev ||= (capistrano_revision_info || svn_revision_info)).blank? > return nil > else > return ''Revision '' + @rev > end > end > end > > # capistrano_revision_info returns the revision number from the REVISION > file > # capistrano_revision_info returns the revision number from `svn info --xml` > > Thanks in advance for any replies.At least I can tell you that it *is* possible to set instance variables in helper methods *and* get them when calling the same helper later on, so the problem must be somewhere else in the code. Did you try going to the console and check what the two methods #capistrano_revision_info and #svn_revision_info actually returns? Maybe that''s the problem, I don''t know, but it''s definitely not the instance variables. -- Cheers, David Knorr http://twitter.com/rubyguy --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
2009/3/20 rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org <rubyguy-DaQTI0RpDDMAvxtiuMwx3w@public.gmane.org>> > > > On 20 Mar., 18:36, Lee D''oéjgi <leedoe...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > > > Can someone tell me why the following isn''t setting an instance variable? > > Perhaps they can''t be set/used in helpers? I have a revision_info method > in > > ApplicationHelper that returns the current SVN revision number (used for > > debugging info in the footer): > > > > module ApplicationHelper > > def revision_info > > logger.info("In revision_info(); rev=#{@rev}") # @rev is always nil > > if (@rev ||= (capistrano_revision_info || svn_revision_info)).blank? > > return nil > > else > > return ''Revision '' + @rev > > end > > end > > end > > > > # capistrano_revision_info returns the revision number from the REVISION > > file > > # capistrano_revision_info returns the revision number from `svn info > --xml` > > > > Thanks in advance for any replies. > > At least I can tell you that it *is* possible to set instance > variables in helper methods *and* get them when calling the same > helper later on, so the problem must be somewhere else in the code. > Did you try going to the console and check what the two methods > #capistrano_revision_info and #svn_revision_info actually returns? > Maybe that''s the problem, I don''t know, but it''s definitely not the > instance variables. > > -- > Cheers, > David Knorr > http://twitter.com/rubyguy > > > But you can only use the member variables from the class(es) which includethe module. James. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
maybe i misunderstand, but what i see is a helper-method in application_helper. i don''t know how many times you call that method in one single view, but if you call it only once @rev is not yet set when you write it into your log file. does the method return your revision-number correctly? if so, why don''t you just write something like this: Footer ... <%= revision_info %> --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---