N00b request help with scaffold- undefined method 'body=' er

Hey guys,

I’m trying to work my way through the Ruby on Rails tutorial building
CRUD actions using scaffold based on a single database table.

the “list” action seems to work well, but all other actions result in
errors.

See trace below …

I am only 2 hours into my Ruby (rails) experience and I have no idea how
to track down this bug.

Here’s the top part of my ResponseController code:

class ResponsesController < ApplicationController
def index
list
render :action => ‘list’
end

def list
@response_pages, @responses = paginate :responses, :per_page => 10
end

def show
@response = Response.find(params[:id])
end

def new
@response = Response.new
end

Any help appreciated!

Thanks!

undefined method `body=’ for #Response:0xb756fed8

RAILS_ROOT: script/…/config/…
Application Trace | Framework Trace | Full Trace

/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.13.2/lib/active_record/base.rb:1498:in
method_missing' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:694:inerase_render_results’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:712:in
erase_results' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:28:inrescue_action’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/rescue.rb:108:in
perform_action' /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/base.rb:369:inprocess_without_session_management_support’
/usr/local/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/session_management.rb:116:in
process' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:indispatch’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in
handle_dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:inservice’
/usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:inrun’
/usr/local/lib/ruby/1.8/webrick/server.rb:173:in start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
/usr/local/lib/ruby/1.8/webrick/server.rb:95:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:instart’
/usr/local/lib/ruby/1.8/webrick/server.rb:23:in start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:instart’
/usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in
dispatch' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
require' /usr/local/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:inrequire’
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in
`require’

If I had this error, I’d guess that I don’t have the attribute “body”
in my “responses” table. Though, I don’t know the particulars of your
setup, so it could be many things.

However, please note that scaffolding is not the preferred way to learn
Rails. And, secondly, there is a rails dedicated group that is probably
a better place for rails questions.

But, anyhow, goodluck with it!

-hampton.

Shouldn’t you also be inheriting from ActionController and not
ApplicationController? Have a look at the ActionController class
(http://rubyonrails.org/api/classes/ActionController/Base.html).
I’ve always thought that ApplicationController was a top-level abstract?

Thanks,

Jeff
(Oh, hi! I don’t post much, but I enjoy reading what everyone else
does =)

end

Hi,

My guess is that “response” is something special in Rails (so is
“request”
if I remember correctly). You are probably overwriting a Rails instance
variable… Try renaming @response to something else. It might even be
your
“Response” model that’s confusing Rails: maybe there is a Response class
in
Rails. Try renaming it to something else…

I hope this will help…

Guillaume

Thanks, Guillaume.

This was the problem. I renamed my controller and things started
working as they were designed.

Thankyou,
na