I am doing a typical database list, but when I do <% for m in @private_messages %> (Line 28) It tells me that the method ''each'' is undefined. What''s wrong, I did not call the method each.... Here''s the error: Showing app/views/account/mail.rhtml where line #28 raised: undefined method `each? for #<PrivateMessage:0x408bb830> Extracted source (around line #28): 25: <th width="69" bgcolor="#F3D54A" scope="col">Reply </th> 26: <th width="71" bgcolor="#EB7761" scope="col">Delete </th> 27: </tr> 28: <% for m in @private_messages %> 29: <tr> etc.. RAILS_ROOT: ../config/.. Application Trace | Framework Trace | Full Trace #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1792:in `method_missing'' #{RAILS_ROOT}/app/views/account/mail.rhtml:28:in `_run_rhtml_account_mail'' Thanks for your help and time -- Posted via http://www.ruby-forum.com/.
My guess is that behind the scenes the interpreter translates the ''in'' construct to ''each'' with a block. A little experimentation confirms the guess: class Foo def each puts ''Each called'' end end f=Foo.new for m in f puts m end www-data wrote:> I am doing a typical database list, but when I do > <% for m in @private_messages %> (Line 28) It tells me that the method > ''each'' is undefined. What''s wrong, I did not call the method each.... > Here''s the error: > Showing app/views/account/mail.rhtml where line #28 raised: > > undefined method `each? for #<PrivateMessage:0x408bb830> > > Extracted source (around line #28): > > 25: <th width="69" bgcolor="#F3D54A" scope="col">Reply </th> > 26: <th width="71" bgcolor="#EB7761" scope="col">Delete </th> > 27: </tr> > 28: <% for m in @private_messages %> > 29: <tr> > etc.. > > RAILS_ROOT: ../config/.. > Application Trace | Framework Trace | Full Trace > > #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1792:in > `method_missing'' > #{RAILS_ROOT}/app/views/account/mail.rhtml:28:in > `_run_rhtml_account_mail'' > > Thanks for your help and time > >-------------- next part -------------- A non-text attachment was scrubbed... Name: rob.vcf Type: text/x-vcard Size: 123 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060816/9bdf4f1d/rob.vcf
Ruby has a method where you could do... for example... @private_messages.each do |m| and that would do a for loop, with each object of @private_messages... basically the same thing you''re trying to do with that for loop... I assume the for loop calls the .each method. Is @private_messages an array? or a Hash.. if it isn''t, it won''t have the .each method. www-data-5 wrote:> > I am doing a typical database list, but when I do > <% for m in @private_messages %> (Line 28) It tells me that the method > ''each'' is undefined. What''s wrong, I did not call the method each.... > Here''s the error: > Showing app/views/account/mail.rhtml where line #28 raised: > > undefined method `each? for #<PrivateMessage:0x408bb830> > > Extracted source (around line #28): > > 25: <th width="69" bgcolor="#F3D54A" scope="col">Reply </th> > 26: <th width="71" bgcolor="#EB7761" scope="col">Delete </th> > 27: </tr> > 28: <% for m in @private_messages %> > 29: <tr> > etc.. > > RAILS_ROOT: ../config/.. > Application Trace | Framework Trace | Full Trace > > #{RAILS_ROOT}/vendor/rails/activerecord/lib/active_record/base.rb:1792:in > `method_missing'' > #{RAILS_ROOT}/app/views/account/mail.rhtml:28:in > `_run_rhtml_account_mail'' > > Thanks for your help and time > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- View this message in context: http://www.nabble.com/Undefined-method---what-undefined-method-tf2117354.html#a5840069 Sent from the RubyOnRails Users forum at Nabble.com.
Is @private_messages an array? or> a > Hash.. if it isn''t, it won''t have the .each method.It''s an array, or a database query @private_messages = PrivateMessage.find_by_to_and_folder(authemail, folder) -- Posted via http://www.ruby-forum.com/.
You want find_all_by_*. find_by_* does a find(:first). The error message is a giveaway: for #<PrivateMessage:0x408bb830> means it is trying to call .each on a PrivateMessage object, not a list of things. Max On 8/17/06, www-data <www-data@andreas-s.net> wrote:> Is @private_messages an array? or > > a > > Hash.. if it isn''t, it won''t have the .each method. > It''s an array, or a database query @private_messages > PrivateMessage.find_by_to_and_folder(authemail, folder) > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >