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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> @upload = Upload.new if @upload.blank?the if statement is the most likely cause -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> the if statement is the most likely causeit should always return false or throw an error if @upload is undefined. I assume this is for if new is called from edit/update were @upload is already defined. try "unless @upload" instead -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-16 23:34 UTC
Re: When Could AR Objects Not Have Their Methods?
Hi -- On Thu, 16 Aug 2007, Hunter Hillegas wrote:> > 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 -%>There''s no line 13. Are you superstitious? :-) I don''t know what the problem is, but I''m curious what would happen if you simply removed the surrounding lines and just had line 14. error_messages_for is smart enough not to bother showing anything if there''s nothing to show. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for responding. I tried changing it to: @upload = Upload.new unless @upload but I''m getting the same error. In the view, I removed the conditional around the error messages helper output and that didn''t help either. It''s strange - it''s like this instance of the ''Upload'' class isn''t properly hooking up with AR - it''s not getting all of the inherited methods... But when used in the console it works fine. This project has nothing in it but the ''attachment_fu'' plugin. Can anyone think of any other code that would be loaded here that could somehow screw up the class loading? On Aug 16, 2007, at 4:06 PM, Keynan Pratt wrote:> >> the if statement is the most likely cause > > it should always return false or throw an error if @upload is > undefined. > I assume this is for if new is called from edit/update were @upload is > already defined. > > try "unless @upload" instead >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2007-Aug-17 00:13 UTC
Re: When Could AR Objects Not Have Their Methods?
Hi -- On Thu, 16 Aug 2007, Hunter Hillegas wrote:> > Thanks for responding. > > I tried changing it to: > > @upload = Upload.new unless @upload > > but I''m getting the same error. > > In the view, I removed the conditional around the error messages > helper output and that didn''t help either. > > It''s strange - it''s like this instance of the ''Upload'' class isn''t > properly hooking up with AR - it''s not getting all of the inherited > methods... But when used in the console it works fine. > > This project has nothing in it but the ''attachment_fu'' plugin. Can > anyone think of any other code that would be loaded here that could > somehow screw up the class loading?You might try changing the name of Upload to Blah or something, just to see if it''s a namespace thing, though I don''t think attachment_fu defines an Upload class. And I assume you''ve checked and double-checked that Upload is inheriting from AR::Base -- that would be the other issue. David -- * Books: RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) RUBY FOR RAILS (http://www.manning.com/black) * Ruby/Rails training & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I was just thinking that so I tried it... Using another class name does seem to work, though I can''t find ''Upload'' in any reserved word list of mentioned at all in attachment_fu. For this one I''ll probably not worry about it and name it something else but I''m surprised I hit this issue as I did check before hand. On Aug 16, 2007, at 5:13 PM, dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote:> You might try changing the name of Upload to Blah or something, just > to see if it''s a namespace thing, though I don''t think attachment_fu > defines an Upload class. And I assume you''ve checked and > double-checked that Upload is inheriting from AR::Base -- that would > be the other issue. >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---