Forum: Ruby on Rails require not working in .rhtml file

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9397b7fcfdce4869a017107edf0e88c1?d=identicon&s=25 Adam Hurlburt (dark_helmut)
on 2008-10-13 05:56
Hello,

I am loading a .rb file from and .rhtml (using an absolute path)and the
.rb file loads fine but then it requires another file (using relative
path) require 'sdl'. I am running apache2 and what is especially strange
is that if I run the url of the .rb file I am requiring in the brower
the server executes the script   fine but when I load it from the .rhtml
file it gives me an error. I have printed the load path and it contains
the directory for the file sdl.rb and I have also tried 'sdl.rb' and it
does not work however it will load if I put the absolute path (require
'/path to file/sdl.rb). The problem with this besides being annoying is
that the file sdl.rb requires a bunch of other files using relative
paths. The problem seems to be that eruby which executes within the
.rhtml file is not loading the same relative paths as ruby however if i
print $: in embedded ruby within the same .rhtml file it clearly states
the correct directoy the file is located in.

The following code is in the file ruby.conf which allows embedded ruby
on the server

<code>
  AddType text/html .rhtml

  <IfModule mod_ruby.c>
  RubyRequire apache/ruby-run
  RubyRequire apache/eruby-run

  # Execute *.rbx files as Ruby scripts
  <Files *.rbx>
  SetHandler ruby-object
  RubyHandler Apache::RubyRun.instance
  </Files>

  # Handle *.rhtml files as eRuby files
  <Files *.rhtml>
  SetHandler ruby-object
  RubyHandler Apache::ERubyRun.instance
  </Files>
  </IfModule>
</code>

Ive spent hours looking through forums and posts and nothing helps
require 'rubygems' does nothing. I will be returning to this post
frequently in the next few days if you need me to post anymore
information just ask.

Any help is appreciated!!Thanks
This topic is locked and can not be replied to.