Hi All,
If you have a has_many association without a defined order on a model and call a method on it through the method_missing method (for example a scope) and then call last on that you'll get an error. To concretize a bit:
Person.posts.active.last
NoMethodError: private method `split' called for nil:NilClass
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1540:in `reverse_sql_order'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1529:in `find_last'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:614:in `find'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1907:in `find_last_by_credits'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1892:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:1892:in `method_missing'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:374:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:374:in `method_missing'
from ./../frontend/vendor/rails/activerecord/lib/active_record/base.rb:2148:in `with_scope'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:206:in `send'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:206:in `with_scope'
from ./../frontend/vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:370:in `method_missing'
from (irb):5
I have submitted a patch to lighthouse for this bug. Please have a look
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2127-broken-find-last-when-no-order-is-given
Regards, Jan De Pooter http://workswithruby.com