Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Rails - undefined method `headers'

49 views
Skip to first unread message

Clay Culver

unread,
Oct 24, 2005, 9:40:53 PM10/24/05
to
Sorry for the complete newbie question, but this seems like it should
be so obvious. I've created a Controller called Welcome. The
welcome_controller.rb contains this:

class WelcomeController < ApplicationController
def index
@response = "hello world"
end
end

I have a view for welcome called "index.rhtml" that contains this:

<html>
<head>
<title>Test</html>
</head>
<body>
<%= @responce %>
</body>
</html>

This seems like it would be a no brainer, but when I go to the page I
get this error:

undefined method `headers' for "":String
Extracted source (around line #46):

43:
44:
45: <h2 style="margin-top: 30px">Response</h2>
46: <b>Headers</b>: <%=h @response.headers.inspect.gsub(/,/, ",\n")
%><br/>

---

What exactly am I doing wrong? I know I could just use render_text but
I'm trying to do something more complex, but I can't seem to make this
work. =/

Devin Mullins

unread,
Oct 24, 2005, 9:52:15 PM10/24/05
to
1. This is the Ruby general list. Please check out the Ruby on Rails
mailing list at http://lists.rubyonrails.org/mailman/listinfo
2. Choose a different variable name than @response. You're getting a
name clash with a variable Rails uses internally.

Devin

Clay Culver

unread,
Oct 24, 2005, 9:54:10 PM10/24/05
to
Whoops, looks like @responce is for other things. I didn't realize
that. =/

Dave Burt

unread,
Oct 24, 2005, 9:55:51 PM10/24/05
to
Clay Culver asked:

You have two problems:
1) You overwrote the built-in variable @response with a string ("hello
world")
2) You misspelt "@responce" in your view.

The answer is simply to change the name of your variable to something Rails
isn't trying to use behind the scenes.

Finally, prefer the Rails community for questions like these: the Freenode
IRC channel and the mailing list.

Cheers,
Dave


0 new messages