PiRSquared17 / activescaffold

Automatically exported from code.google.com/p/activescaffold
MIT License
0 stars 0 forks source link

links_for_association called before the config block is run #768

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create an empty model with a non existent association
2. Create an associated controller 
3. In the controller add an active_scaffold_for :model_name{|config| 
config.columns = []; config.actions.exclude [:list]
4. Start a mongrel server

It is easier to look at the code then it is too reproduce the problem. In my 
particular case the real issue is in the active_support load_missing_constant. 
Not active_scaffold.

However, that said this is potentially a performance issue. 

If you look at active_scaffold/lib/active_scaffold.rb,

ClassMethods#active_scaffold(model_id = nil, &block)

You can see that links_for_associations is called well before the configuration 
block is actually run. (self.active_scaffold_config.configure &block if 
block_given?)

"Despite this comment above links_for_associations
 # Create the automatic column links. Note that this has to happen when configuration is *done*, because otherwise the Nested module could be disabled. Actually, it could still be disabled later, couldn't it?
    def links_for_associations" (Link 104 in my version)

What is the expected output? What do you see instead?
Expected - There should be no error. The links_for_association should return 
without looking for any associations, since their are no associations listed in 
the configuration.columns. (In fact there are no columns at all).

Instead - An error occurs that includes links_for_associations in the stack 
trace (even though it shouldn't be iterating over any columns) 

What version (or revision) of the product are you using?
rails-2.3

If this bug causes an exception, please paste at least the first 20 lines
below of a full backtrace (with backtrace silencers removed).

in my perticular case vector_graphics_groups_controller is an activescaffold 
for AIBS::VectorGraphics::Group which has an association to 
AIBS::VectorGraphics::GraphicObjects (thus the load error)

/local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support
/dependencies.rb:426:in `load_missing_constant': Expected 
/home/skyf/LIMS2/tech/lims_m7.5/lib/aibs/vector_graphics.rb to define 
Aibs::VectorGraphics (LoadError)
        from /local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/dependencies.rb:80:in `const_missing'
        from /local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:364:in `constantize'
        from /local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `each'
        from /local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/inflector.rb:363:in `constantize'
        from /local1/ruby-1.8.7/lib/ruby/gems/1.8/gems/activesupport-2.3.8/lib/active_support/core_ext/string/inflections.rb:162:in `constantize'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:195:in `active_scaffold_controller_for'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:193:in `each'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:193:in `active_scaffold_controller_for'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:192:in `each'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:192:in `active_scaffold_controller_for'
        from /home/skyf/LIMS2/tech/lims_m7.5/app/controllers/application_controller.rb:67:in `active_scaffold_controller_for'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:118:in `links_for_associations'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold/data_structures/columns.rb:62:in `each'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:107:in `links_for_associations'
        from /home/skyf/LIMS2/tech/lims_m7.5/vendor/plugins/active_scaffold/lib/active_scaffold.rb:59:in `active_scaffold'
        from /home/skyf/LIMS2/tech/lims_m7.5/app/controllers/vector_graphics_groups_controller.rb:7

Original issue reported on code.google.com by diedthre...@gmail.com on 18 Nov 2010 at 12:57

GoogleCodeExporter commented 9 years ago
links_for_associations must be run before configuration block or you can't 
tweak link or remove column link. It was moved after configuration block some 
time ago, and it won't work right, so it had to be moved before block again.

If you association were right defined you wouldn't get any error.

Original comment by sergio.c...@gmail.com on 19 Nov 2010 at 8:40