Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Rails - undefined method `headers'

Reply
Thread Tools

Rails - undefined method `headers'

 
 
Clay Culver
Guest
Posts: n/a
 
      10-25-2005
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. =/

 
Reply With Quote
 
 
 
 
Devin Mullins
Guest
Posts: n/a
 
      10-25-2005
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 wrote:

>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. =/
>
>
>
>
>




 
Reply With Quote
 
 
 
 
Clay Culver
Guest
Posts: n/a
 
      10-25-2005
Whoops, looks like @responce is for other things. I didn't realize
that. =/

 
Reply With Quote
 
Dave Burt
Guest
Posts: n/a
 
      10-25-2005
Clay Culver asked:
> 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. =/


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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefine Method Only Marks the Method Undefined Su Zhang Ruby 3 04-18-2011 12:11 AM
Undefined method errors in rails Daniel Mendler Ruby 0 03-14-2008 03:56 AM
typeof x == 'undefined' or x == undefined? -Lost Javascript 13 01-31-2007 12:04 AM
undefined vs. undefined (was: new Array() vs []) VK Javascript 45 09-12-2006 05:26 PM
undefined behavior or not undefined behavior? That is the question Mantorok Redgormor C Programming 70 02-17-2004 02:46 PM



Advertisments