2012-04-28 17 views
1

最近Apacheをerubyで構成し、いくつかのrhtmlページを実行しました。私はglobalfunctions.rbファイルを持っています。このファイルは、サイト上で実行しているすべてのページで利用できるようにしたいものです。ErubyでApacheがrequire文を正しく解析しない

はしかし、私は問題を抱えている:RHTMLで必要と文は、それがエラー500を破ると返します入れてここにページのコードです:

<html> 
<head> 
    <title>Home | Quantum Software</title> 
    <link rel="stylesheet" type="text/css" href="style.css" /> 
</head> 
<body> 
<% 
require './globalfunctions.rb' 
%> 
<div class="contentBox"> 

</div> 
</body> 
</html> 

とグローバル関数ファイル:

def get_file_name() 
    return File.basename(__FILE__) 
end 

def new_nav_link(target, title) 
    currentFileName = get_file_name() 

    if target == currentFileName 
     puts %[email protected]<a href="#{target}" class="selected">#{title}</a>@ 
    else 
     puts %[email protected]<a href="#{target}">#{title}</a>@ 
    end 
end 

そして最後に、ここのerror.logの最後の数行です:あなたのための

[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] : 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] no such file to load -- ./globalfunctions.rb 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] (
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] LoadError 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103]) 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] --- generated code --- 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<html>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<head>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\t<title>Home | Quantum Software</title>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\t<link rel=\\"stylesheet\\" type=\\"text/css\\" href=\\"style.css\\" />\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</head>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<body>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] require "./globalfunctions.rb" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "<div class=\\"contentBox\\">\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</div>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</body>\\n" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] print "</html>" 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] ---------------------- 
[Fri Apr 27 23:22:59 2012] [error] [client 174.252.185.103] Premature end of script headers: eruby 
[Fri Apr 27 23:23:24 2012] [error] an unknown filter was not added: includes 
[Fri Apr 27 23:23:24 2012] [error] an unknown filter was not added: includes 
[Fri Apr 27 23:24:04 2012] [error] an unknown filter was not added: includes 
[Fri Apr 27 23:27:03 2012] [error] an unknown filter was not added: includes 

おかげで事前に助けてください。

答えて

2

印刷アウトあなたのRHTMLファイル内$LOAD_PATHDir.pwd

<!-- For example like this --> 
<p> 
    The load path is: <br /> 
    <%= $LOAD_PATH.join("<br />\n") %> 
</p> 
<p> 
    The current working directory is: <%= Dir.pwd %> 
</p> 

おそらく、Rubyインタプリタの現在の作業ディレクトリ(Dir.pwdが)あなたのRHTMLファイルの場所と同じではないことがわかります。だからRubyはでしか見つからないのでglobalfunctionsを見つけることができません。

require '/var/www/mypages/globalfuntions' 

または代わりに、あなたのglobalfuntions.rbいずれかの任意のディレクトリ内に、または所定の位置に$LOAD_PATHポイント(へDir.pwdポイントということを置く:あなたのような、絶対パスを使用してファイルを要求する必要があり、その場合には

Rubyインタプリタの現在の作業ディレクトリ)。

+0

ありがとう、それはトリックでした! – Mark

関連する問題