#62 ✓resolved
Mathijs Kwik

[fix] apply_scopes somehow breaks stuff when none of the scopes are applied.

Reported by Mathijs Kwik | July 22nd, 2008 @ 10:57 PM

On edge hobo and rails 2.1 the following code (borrowed from the agility tutorial) breaks in some cases:

  def show
    @project = find_instance
    @project_stories = @project.stories.apply_scopes(:search => [params[:search], :title],
                                                     :order_by => parse_sort_param(:title, :status))
  end

errors when no search and no order params are given:

 NoMethodError in Projects#show

Showing projects/show.dryml where line #3 raised:

undefined method `member_class' for #<Class:0x7f56e43999b8>

Extracted source (around line #3):

1: <show-page>
2:   <primary-collection:>
3:     <table-plus fields="this, tasks.count, status">
4:       <empty-message:>No stories match your criteria</empty-message:>
5:     </table-plus>
6:   </primary-collection:>

RAILS_ROOT: /mnt/data/projects/agility
Application Trace | Framework Trace | Full Trace

vendor/rails/activerecord/lib/active_record/base.rb:1667:in `method_missing_without_paginate'
vendor/plugins/will_paginate/lib/will_paginate/finder.rb:164:in `method_missing'
vendor/plugins/hobo/lib/hobo/model.rb:302:in `method_missing'
vendor/plugins/hobo/taglibs/rapid_plus.dryml:3:in `table_plus'
vendor/plugins/hobo/lib/hobo/dryml/template_environment.rb:273:in `_tag_context'
vendor/plugins/hobo/lib/hobo/dryml/template_environment.rb:232:in `new_context'
vendor/plugins/hobo/lib/hobo/dryml/template_environment.rb:273:in `_tag_context'
vendor/plugins/hobo/taglibs/rapid_plus.dryml:1:in `table_plus'
app/views/projects/show.dryml:3:in `render_page'
app/views/projects/show.dryml:2:in `render_page'
app/views/taglibs/themes/clean/clean.dryml:2:in `page'
app/views/taglibs/themes/clean/clean.dryml:1:in `page'
app/views/projects/show.dryml:1:in `render_page'
app/views/projects/show.dryml:1:in `render_page'

this is very strange behavior, since apply_scopes should just return self if no scopes should apply. I tried (for testing) changing apply_scopes to

def apply_scopes(scopes)
  self
end

and found that the error persists.

Looks like returning self somehow breaks out of one of the scopes (proxy_found stuff), but my metaprogramming-skills aren't good enough to track the exact source of the problem.

Comments and changes to this ticket

  • Mathijs Kwik

    Mathijs Kwik July 22nd, 2008 @ 11:04 PM

    • Title changed from “[bug] apply_scopes somehow breaks stuff when none of the scopes are applied.” to “[bug/workaround] apply_scopes somehow breaks stuff when none of the scopes are applied.”

    Hmm... looks like I found a dirty workaround, no idea why it works, just thought about scoping self at least once, and it seems it does the trick. Don't really like it though. Maybe someone can have a deeper look into it.

    diff --git a/hobo/lib/hobo/scopes/apply_scopes.rb b/hobo/lib/hobo/scopes/apply_scopes.rb
    index b87a8eb..41c2717 100644
    --- a/hobo/lib/hobo/scopes/apply_scopes.rb
    +++ b/hobo/lib/hobo/scopes/apply_scopes.rb
    @@ -5,7 +5,7 @@ module Hobo
         module ApplyScopes
    
           def apply_scopes(scopes)
    -        result = self
    +        result = self.scoped({})
             scopes.each_pair do |scope, arg|
               if arg.is_a?(Array)
                 result = result.send(scope, *arg) unless arg.first.blank?
    
  • Mathijs Kwik

    Mathijs Kwik July 25th, 2008 @ 02:10 AM

    My previous solution was indeed dirty, it just looked as if it worked.

    final fix for apply_scopes and other scoping-related stuff in my github-fork:

    http://github.com/bluescreen303/...

  • Mathijs Kwik

    Mathijs Kwik July 25th, 2008 @ 11:46 AM

    • Title changed from “[bug/workaround] apply_scopes somehow breaks stuff when none of the scopes are applied.” to “[fix] apply_scopes somehow breaks stuff when none of the scopes are applied.”
  • Tom Locke

    Tom Locke July 28th, 2008 @ 07:47 PM

    • State changed from “new” to “resolved”

    Thanks Mathijs

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Pages