ron
June 18, 2008, 9:55pm
1
So I generate a scaffold with Rails 2.1.0 with a number of database
fields.
item:string accession_number:text description:text designer:string
classification:string overall_dimensions:string auxiliary_parts:string
overall_condition:string condition_description:text picture:binary
accession_date:datetime provenance:text manufacturer:string
design_date:string construction_date:datetime
material_surface_finish:string medium_technique:string
identification_markings:string picture2:binary recommendations:string
exhibition_record:string conservation_record:string bibliography:text
dimensions:string notes:text class:string old_box_numbers:string
other_identification_numbers:string inventory_date:datetime
inventory_recorded_by:string other_source_location_information:text
other_location_information:text location:text box_number:integer
collector:string collector_or_donor:string
archaeological_site_name:string archaeology_site_number:string
geographical_region:string picture1desc:text picture2desc:text
insurance_appraisal:string
And when I go to the scaffold new view, it tells me I have a nill
object where I didn’t expect it. Normally, this happens when I
haven’t specified the id of an Active Record object properly so the
Controller doesn’t give the View a specific active Record object to
play with.
But in this case the model is simply Entry and my controller code is
simply @entry=Entry.new. I can’t see where that wouldn’t give it an
object to play with?
Ron
ron
June 18, 2008, 10:01pm
2
On Jun 18, 2008, at 3:54 PM, Ron wrote:
exhibition_record:string conservation_record:string bibliography:text
dimensions:string notes:text class:string old_box_numbers:string
OK, this is more of a wild guess than anything, but could your column
‘class’ be a problem? If not, you probably have to look at the link
in your view where the error is thrown.
haven’t specified the id of an Active Record object properly so the
Controller doesn’t give the View a specific active Record object to
play with.
But in this case the model is simply Entry and my controller code is
simply @entry=Entry.new. I can’t see where that wouldn’t give it an
object to play with?
Ron
Rob B. http://agileconsultingllc.com
[email protected]
ron
June 20, 2008, 6:37pm
3
Hi Rob,
So I tried changing class to type, without any success. I checked
the development log and found the following entry:
ActionView::TemplateError (You have a nil object when you didn’t
expect it!
The error occurred while evaluating nil.generated_methods) on line #8
of entries/new.html.erb:
5:
6:
7: <%= f.label :dimensions %>
8: <%= f.text_field :dimensions %>
9:
10:
11: <%= f.label :cultural_affiliation %>
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
attribute_methods.rb:343:in respond_to?' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ helpers/form_helper.rb:622:in
value_before_type_cast’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
helpers/form_helper.rb:612:in value_before_type_cast' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ helpers/form_helper.rb:535:in
to_input_field_tag’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
helpers/form_helper.rb:358:in text_field' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ helpers/form_helper.rb:709:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
helpers/form_helper.rb:709:in text_field' app/views/entries/new.html.erb:8:in
_run_erb_47app47views47entries47new46html46erb’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
helpers/form_helper.rb:317:in fields_for' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ helpers/form_helper.rb:253:in
form_for’
app/views/entries/new.html.erb:3:in
_run_erb_47app47views47entries47new46html46erb' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ base.rb:338:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
base.rb:338:in execute' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ template_handlers/compilable.rb:29:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
template_handlers/compilable.rb:29:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ template.rb:35:in
render’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
template.rb:22:in render_template' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ base.rb:245:in
render_file’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:1108:in render_for_file' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:865:in
render_with_no_layout’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:880:in render_with_no_layout' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ layout.rb:251:in
render_without_benchmark’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:51:in render' /Library/Ruby/Gems/1.8/gems/activesupport-2.1.0/lib/active_support/ core_ext/benchmark.rb:8:in
realtime’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
benchmarking.rb:51:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ mime_responds.rb:131:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
mime_responds.rb:131:in custom' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ mime_responds.rb:160:in
call’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
mime_responds.rb:160:in respond' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ mime_responds.rb:154:in
each’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
mime_responds.rb:154:in respond' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ mime_responds.rb:107:in
respond_to’
app/controllers/entries_controller.rb:29:in new' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:1162:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:1162:in perform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:580:in
call_filters’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
filters.rb:573:in perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ benchmarking.rb:68:in
perform_action_without_rescue’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/1.8/benchmark.rb:293:in measure' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ benchmarking.rb:68:in
perform_action_without_rescue’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
rescue.rb:201:in perform_action_without_caching' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ caching/sql_cache.rb:13:in
perform_action’
/Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/
connection_adapters/abstract/query_cache.rb:33:in cache' /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/ query_cache.rb:8:in
cache’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
caching/sql_cache.rb:12:in perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:529:in
send’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
base.rb:529:in process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ filters.rb:569:in
process_without_session_management_support’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
session_management.rb:130:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ base.rb:389:in
process’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:149:in handle_request' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:107:in
dispatch’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:104:in synchronize' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:104:in
dispatch’
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/
dispatcher.rb:120:in dispatch_cgi' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_controller/ dispatcher.rb:35:in
dispatch’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:76:in process' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in
synchronize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/rails.rb:74:in process' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:159:in
process_client’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:158:in
process_client’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in
initialize’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in new' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:285:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in initialize' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in
new’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel.rb:268:in run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:282:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in
each' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/configurator.rb:281:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:128:in run' /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ ruby/gems/1.8/gems/mongrel-1.1.4/lib/mongrel/command.rb:212:in
run’
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/
ruby/gems/1.8/gems/mongrel-1.1.4/bin/mongrel_rails:281
/usr/bin/mongrel_rails:19:in `load’
/usr/bin/mongrel_rails:19
Rendering /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/
action_controller/templates/rescues/layout.erb (internal_server_error)
Any thoughts?
Thanks,
Ron
On Jun 18, 1:01 pm, Rob B. [email protected]
ron
June 20, 2008, 7:03pm
4
Ron,
First, ‘type’ isn’t much better than ‘class’ since ‘type’ is used to
indicate Single-Table Inheritance in ActiveRecord.
Now, I first looked to see if ‘dimensions’ was actually a database
column. Seems like it is (and spelled consistently in both places,
too). I can’t try to replicate your error because I don’t have 2.1
installed, but can you avoid it by commenting out line 8? (<%# is an
erb comment)
Do other text_field calls for this object then work? From the low
line number, I’m guessing that this is the first text_field in your
view.
I may not be helping you much, but this is the kind of controlled
descent I’d make into the rabbit hole.
-Rob
ron
June 20, 2008, 7:19pm
5
So I tried changing type/class to something completely random–in this
case binder. (I call my variables that when I’m frustrated–I know,
its weird).
So, its still coming up. I even tried changing dimensions value when
I did that. I wonder if my name for the controller is reserved,
entry? None of the other text fields for the scaffold actually work.
Really strange.
btw… I LOVE that phrase “controlled descent into the rabbit hole.”
I’m going to use it down the road, if that’s ok.
Ron
On Jun 20, 10:03 am, Rob B. [email protected]
ron
June 20, 2008, 7:50pm
6
Ahaha…so I fixed it. It was just that entry, my name for the model,
was a reserved word.
R
ron
June 20, 2008, 6:50pm
7
I have seen the error message
The error occurred while evaluating nil.generated_methods)
when you use a Rails reserved name
field name “class” is most common offender, may be “type” as well.
Change it to something totally different and see what happens.
-Hari
ron
June 20, 2008, 7:54pm
8
Glad you found it. The phrase is free to use, but only if you use it
wisely.
-Rob
On Jun 20, 2008, at 1:49 PM, Ron wrote:
its weird).
Ron
too). I can’t try to replicate your error because I don’t have 2.1
expect it!
/Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/
_run_erb_47app47views47entries47new46html46erb' /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/action_view/ action_controller/ /Library/Ruby/Gems/1.8/gems/actionpack-2.1.0/lib/ mime_responds.rb:160:in
call’
action_controller/
item:string accession_number:text description:text
exhibition_record:string conservation_record:string
inventory_recorded_by:string
the
Ron
Rob B. http://agileconsultingllc.com
[email protected]
Rob B. http://agileconsultingllc.com
[email protected]
+1 513-295-4739
Skype: rob.biedenharn
ron
June 25, 2008, 2:24am
9
Hmmm…
I have a table called ‘entries’ and a model named ‘entry’ in my app
and it works.
Rails 2.0.2