# Scope

**URL:** <https://www.ruby-forum.com/t/scope/99563>\
**Category:** Rails\
**Created:** [July 24, 2006, 4:05am UTC](https://www.ruby-forum.com/t/scope/99563 "2006-07-24T04:05:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [July 24, 2006, 4:05am UTC](https://www.ruby-forum.com/t/scope/99563/1 "2006-07-24T04:05:16Z")

</div>

At my day job this week we released an account manager app that lets  
people view/manage/pay their bills.

It’s a C# .net app, I designed the interface (css, html, js), 10 others  
did the actual .net stuff (too many cooks that can’t boil water).

It went live, and bad things started to happen. Customer 1 could see  
customer 2’s billing data, customer 2 would accidentally pay customer  
3’s bill. It was all due to some “shared” variables getting overwritten  
when customers would do the same action at relatively the same time.

My question is, is this something I should worry about with ROR/Ruby?  
and or caching?

Thanks!

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [July 24, 2006, 4:19am UTC](https://www.ruby-forum.com/t/scope/99563/2 "2006-07-24T04:19:14Z")

</div>

On 7/23/06, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> when customers would do the same action at relatively the same time.
> 
> My question is, is this something I should worry about with ROR/Ruby?  
> and or caching?
> 
> Thanks!

If you’re sloppy, yes. Don’t be sloppy 🙂

And really, this shouldn’t be an issue with C# either.

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [July 24, 2006, 4:36am UTC](https://www.ruby-forum.com/t/scope/99563/3 "2006-07-24T04:36:59Z")

</div>

Daniel ----- wrote:

> Hope this helps

That does, thanks a bunch!

Am half way through my first ROR app and  
haven’t quite gotten to caching yet. Since I’m the only  
one viewing the data at one time, just didn’t want to  
have a problem when I get ready for prod.

And yes, I work with a group of hacks/drag-n-drop kings.  
Gotta love the corporate world.

Thanks again.

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [July 24, 2006, 4:29am UTC](https://www.ruby-forum.com/t/scope/99563/4 "2006-07-24T04:29:43Z")

</div>

On 7/24/06, David C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 3’s bill. It was all due to some “shared” variables getting overwritten
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Yes. When you cache you should use fragment cache. Include in the cache  
call a user id. the cache method accepts a hash like url for but it can  
be  
anything. You’re not restricted to real things (controllers/actions  
etc).  
If you don’t include somthing to seperate it by user, each user may get  
the  
same cached fragment.

an eg might be

\<% cache( :controller =\> ‘bill’, :action =\> ‘show\_last\_10’, :user =\>  
current\_user.id ) do -%\>  
\<%= all your cached frag -%\>  
\<% end %\>

This will scope the fragment to those parameters, and you can re-use it  
elsewhere if you want. Just include the same url in the cache.

Be sure to expire the fragment if the data changes. expire\_fragment(  
same\_url\_hash\_used\_in\_cache\_call )

Also the mean\_time filter plugin is worth a look. with it you can put a  
scope call around a whole controller or parts of it.

Hope this helps

---

<div class="post-metadata">

**Author:** ![pezdude](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a87d85/32.png) [@pezdude](https://www.ruby-forum.com/u/pezdude)\
**Post date:** [July 24, 2006, 4:54am UTC](https://www.ruby-forum.com/t/scope/99563/5 "2006-07-24T04:54:41Z")

</div>

Personally, I wouldn’t be caching anything until the app is done and  
tested. Then if you actually need caching go back and put it in where  
it’s really necessary, as determined by testing and benchmarking.  
With payment/billing systems especially be a bit conservative. Every  
additional feature you add is one more thing that can break in  
unexpected ways due to software upgrades, code changes, etc… I also  
freeze a copy of rails and all the gems that I use in the vendor  
directory for apps like this. Ruby and rails is a fast moving target,  
and there is no way you can keep up with all the changes to rails,  
gems, plugins, etc…

Chris
