Jano Svitok wrote:
> On Wed, Apr 30, 2008 at 10:08 PM, James Nykiel wrote:
>> Hi,
>>
>>  I am new to Ruby / eRuby templating and need some help converting from
>>  PHP, I have two web pages that do what I need using PHP but I can figure
>>  out how to do the same with Ruby / eRuby templating, could  someone
>>  please have a look and guide me?
>>
>>  What seems to be happening is that the Ruby / eRuby variable? $file is
>>  being set to menu.rhtml while the PHP variable? $file is being set to
>>  index.php, which is what I want the Ruby / eRuby to do also.
> 
> Hi,
> 
> try using ENV['SCRIPT_FILENAME'] or $0 instead of __FILE__.
> 
> __FILE__ is always the name of *current* file (i.e. the one being 
> parsed).
> $0 is the name of the "started" file (the one that was started from 
> outside).
> SCRIPT_FILENAME is CGI variable.
> 
> Note: not tested, just hints.
> 
> Jano

Jano,

Thanks for the hint, got it working!

This is the change that I made to make things work the way I needed.

## Ruby / eRuby ##

# menu.rhtml
# Menu item name is non-link if page name is the same as menu item name,
if not then menu item name is link.

<%

fname = File.basename ENV['SCRIPT_FILENAME']

if fname == 'index.rhtml'
puts 'Home &nbsp;&nbsp;::&nbsp;&nbsp;'

else
puts '<a href="index.rhtml" title="Home">Home</a> 
&nbsp;&nbsp;::&nbsp;&nbsp;'
end

%>

-- 
Posted via http://www.ruby-forum.com/.