Forum: Ruby on Rails undefined method `include'

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.
CSN (Guest)
on 2005-12-28 23:38
(Received via mailing list)
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/...

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/
Chris Lowder (Guest)
on 2005-12-29 01:09
(Received via mailing list)
have you just tried running the code without the include statement?
>From my experience all you need to do is have require.
csn (Guest)
on 2005-12-29 21:25
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. (Guest)
on 2005-12-31 10:47
(Received via mailing list)
On 29/12/05, csn <removed_email_address@domain.invalid> 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/
csn (Guest)
on 2005-12-31 21:30
Dick D. wrote:
> On 29/12/05, csn <removed_email_address@domain.invalid> 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
This topic is locked and can not be replied to.