[Rails] Re: Getting data from the database only once

Daniel N
Tue, 25 Jul 2006 06:04:28 -0000

On 7/25/06, Ezra Zygmuntowicz <ezmobius@gmail.com>
wrote:
>
>
> On Jul 24, 2006, at 10:36 PM, Anand Srinu wrote:
>
> > I think I will rephrase my question.
> >
> > I have an application.
> > I have one table, states(which holds the details regarding the
> > different
> > states) . In one controller(say sign_up_controller.rb), I need all the
> > states to display in a combo box in a rhtml page.
> >
> > for getting all the states I use  get_states = States.find(:all). I
> > get
> > all the states and display in the rhtml page.
> >
> > Now in another controller (say friends_details_controller.rb), I again
> > require all the states. This time If I wanna get the states, I need to
> > quiery again to the SQl. right??
> >
> > I dont want to do that...
> > <snip>
> >
> > Thanks for making me clear what I wanted....
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> > _______________________________________________
> > Rails mailing list
> > Rails@lists.rubyonrails.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
>
> Anand-
>
>         I think what you want is fragment caching. This way you could do
> the
> query once and rails can store the results on disk so next time you
> need it it will be served from the cache and not hit the db. Here are
> a few links to get you started.
>
>
> http://rails.rubyonrails.com/classes/ActionController/Caching/
> Fragments.html
> http://scottstuff.net/presentations/rails-caching/
>
>
> Cheers-
> -Ezra
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails


Ezra,

Would this cause issues if say, different options need to be selected based
on object values or different defaults for different views?

Wouldn''t a fragment cached version be permenantly selected on one
option by
default?
-------------- next part --------------
An HTML attachment was scrubbed...