Colin Law wrote in post #986452:
> On 9 March 2011 11:54, Frederick Cheung <frederick.che...@gmail.com>
> wrote:
>
> OK, I provided a scope
> scope :all_varieties
> with no parameters.
>
> Then in the controller
> @varieties = Variety.all_varieties
> and have confirmed that if the fragment is already cached so
> @varieties is not used in the view, then the query is not run, so no
> need test whether the fragment exists when setting up @varieties.
>
> This is the best solution I think.
>
> Thanks again
>
> Colin

Ack... obfuscated logic.  If you are trying to not make the call when 
the cache fragment already exists, then don't do so.

@varieties = Variety.all unless fragment_exist?( 'select_box' )

Don't squirrel it away behind a scope which does nothing except let you 
defer the decision about executing the DB read and depend on a behavior 
of AR which is determined when the view is being rendered...

Just a personal opinion.  What works for you, works for you.

-- 
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@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to