Undefined method `include'

I’m getting this error in Rails:

undefined method `include’ for
#MenusController:0x408efd1c

The offending code is:

require “rexml/document”
include REXML

I see there may be a problem with GCC 4 on OSX, but
I’m using Redhat with GCC 3.2.
http://weblog.rubyonrails.org/articles/2005/12/22/is-gcc-4-0-incompatible-with-ruby-on-os-x-and-elsewhere

I’ve tried the above code with the command line and it
works fine. Any idea what the problem is?

thanks
csn


Yahoo! for Good - Make a difference this year.
http://brand.yahoo.com/cybergivingweek2005/

have you just tried running the code without the include statement?

From my experience all you need to do is have require.

Chris Lowder wrote:

have you just tried running the code without the include statement?

From my experience all you need to do is have require.

This line caused an error:
responsedoc = Document.new(response)

But changing it to this works:
responsedoc = REXML::Document.new(response)

Further commandline vs. Rails weirdness is that in Rails this returns an
empty string:
response=open(url)

But this works:
response=Net::HTTP.get(URI.parse(url))

I don’t know why include and open work in the commandline, but not in
Rails. Some config setting perhaps? Definitely an exasperating
experience.

csn

Dick D. wrote:

On 29/12/05, csn [email protected] wrote:

in Rails this returns an empty string:
response=open(url)

But this works:
response=Net::HTTP.get(URI.parse(url))

I don’t know why include and open work in the commandline, but not in
Rails. Some config setting perhaps? Definitely an exasperating
experience.

Are you sure open works? On a straight commandline, you’ll be using
Kernel.open, which returns an IO object for a file/directory.
It doesn’t know about URIs.

Try loading open-uri, and calling it on the string

require ‘open-uri’

response = url.open

If you want the content, just replace the last line with

page = url.open.readlines

Yeah, I had “require ‘open-uri’” in there. You’re right - without it,
Kernel.open can’t open the URL (I thought I remembered reading in the
docs that Kernel.open could handle URLs though).

csn

On 29/12/05, csn [email protected] wrote:

in Rails this returns an empty string:
response=open(url)

But this works:
response=Net::HTTP.get(URI.parse(url))

I don’t know why include and open work in the commandline, but not in
Rails. Some config setting perhaps? Definitely an exasperating
experience.

Are you sure open works? On a straight commandline, you’ll be using
Kernel.open, which returns an IO object for a file/directory.
It doesn’t know about URIs.

Try loading open-uri, and calling it on the string

require ‘open-uri’

response = url.open

If you want the content, just replace the last line with

page = url.open.readlines


Rasputin :: Jack of All Trades - Master of Nuns
http://number9.hellooperator.net/