I’m seeing something strange and so far haven’t been able to figure
it out. First off, here’s our setup:
MacOS X Tiger 10.4.10 (Intel)
Ruby 1.8.6
Rails 1.2.3
PostgreSQL 8.2.3
I have a ton of apps that work great but a brand new app is giving me
trouble.
I am getting an error indicating that the ‘errors’ method for the
object doesn’t exist. It should be inherited from the base AR class.
This app has a single model, ‘Upload’ that uses attachment_fu to take
uploads.
Here’s my code:
Model:
class Upload < ActiveRecord::Base
has_attachment :storage => :file_system, :max_size => 5.megabytes
end
Controller:
def new
@upload = Upload.new if @upload.blank?
end
View:
<% form_for :upload, @upload, :url => {:action => :create} do |form| %>
<% if @upload != nil && !@upload.errors.empty? -%>
<%= error_messages_for ‘upload’ %>
<% end -%>
<% end %>
The error I get is:
ActionView::TemplateError (undefined method `errors’ for #<Upload:
0x34e5e14>) on line #12 of app/views/uploads/new.rhtml:
12: <% if @upload != nil && !@upload.errors.empty? -%>
14: <%= error_messages_for ‘upload’ %>
15: <% end -%>
#{RAILS_ROOT}/app/views/uploads/new.rhtml:12:in
_run_rhtml_47app47views47uploads47new46rhtml' /opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/ action_view/helpers/form_helper.rb:151:in
fields_for’
/opt/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/
action_view/helpers/form_helper.rb:127:in form_for' #{RAILS_ROOT}/app/views/uploads/new.rhtml:4:in
_run_rhtml_47app47views47uploads47new46rhtml’
Huh?
When I put in some debugging code, it gets even more interesting:
I added this code to the controller:
logger.debug "Upload Class: #{@upload.class}"
logger.debug @upload.methods
Ok, this should tell me more. Output:
Upload Class: Upload
inspectinstance_execlistenerclonemethodrequire_gemrequire_library_or_gem
request_progresspublic_methodsencode64blank?
listener=instance_variable_defined?decode64equal?
freezeunloadableloadb64encodemethodssilence_warningsrespond_to?
enable_warningsreturningremove_subclasses_ofdupto_yamlinstance_variables
optionsdecode_b__id__object_ideql?
requireidprocesssilence_streamrequest_beginssingleton_methodsto_yaml_sty
lesendwith_optionstaintfrozen?instance_variable_getgeminstance_of?
__send__to_aextend_with_included_modules_fromrequest_notify`typeinstance
_evalprotected_methodsto_yaml_propertiesdisplay=====subclasses_ofinstanc
e_variable_setsilence_stderrextended_byextendkind_of?
to_sdaemonizeinstance_valuesclasshashto_paramprivate_methods=~tainted?
suppresstagurito_jsonuntaintnil?
copy_instance_variables_fromtaguri=dcloneis_a?
So, it is the right class but the methods are wrong.
What the heck is going on here? When I create a new Upload object
from the console, everything works properly and the methods are all
there.
What gives?
Thanks,
Hunter