Instance variables in helpers?


#1

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


#2

On 20 Mar., 18:36, Lee D’oéjgi removed_email_address@domain.invalid wrote:

if (@rev ||= (capistrano_revision_info || svn_revision_info)).blank?

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 K.
http://twitter.com/rubyguy


#3

2009/3/20 removed_email_address@domain.invalid removed_email_address@domain.invalid

debugging info in the footer):
end
helper later on, so the problem must be somewhere else in the code.
But you can only use the member variables from the class(es) which include
the module.
James.


#4

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 %>