# Viewstate and Context in rails

**URL:** <https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159>\
**Category:** Rails\
**Created:** [January 6, 2008, 12:24pm UTC](https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159 "2008-01-06T12:24:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [January 6, 2008, 12:24pm UTC](https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159/1 "2008-01-06T12:24:54Z")

</div>

Hello,

I want to know if RoR support Viewstate and Context like [ASP.net](http://ASP.net) or not,  
and if not, does RoR support another technique to save date other than  
session?

thanks in advanced.

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [January 7, 2008, 8:00pm UTC](https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159/2 "2008-01-07T20:00:42Z")

</div>

On 1/6/08, Mohamed S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to know if RoR support Viewstate and Context like [ASP.net](http://ASP.net) or not,  
> and if not, does RoR support another technique to save date other than  
> session?

There’s memcached:

> **[memcached - a distributed memory object caching system](http://memcached.org/)**
>
> memcached

[http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails](http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails)

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [January 7, 2008, 9:13pm UTC](https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159/3 "2008-01-07T21:13:26Z")

</div>

On Jan 7, 2008, at 11:00 AM, Greg D. wrote:

> [http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails](http://nubyonrails.com/articles/2006/08/17/memcached-basics-for-rails)

And regarding the OP’s question about Viewstate, the answer is no. The  
main logic behind Viewstate seems, to me, to be lightening the load of  
populating complicated [Asp.Net](http://Asp.Net) controls. The cost of that is that you  
have to ship an encrypted hidden field called Viewstate round-trip for  
each page served. This can get pretty bandwidth intensive but it’s all  
about tradeoffs.

Rails doesn’t have any of these controls, so repopulation is done in  
whatever programmatic way you, as the developer want. It doesn’t  
always make sense to repopulate controls – just in cases where there  
has been, for example, an error in data entry. That means that for the  
error cases, you typically spit back the fields that posted and  
validated, and blank the rest (all of this is automatic if you follow  
convention).

Is there any other compelling reason to use Viewstate on a [non-Asp.Net](http://non-Asp.Net)  
app that I’m not aware of?

---

<div class="post-metadata">

**Author:** ![shafi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/439d5e/32.png) [@shafi](https://www.ruby-forum.com/u/shafi)\
**Post date:** [January 7, 2008, 10:33pm UTC](https://www.ruby-forum.com/t/viewstate-and-context-in-rails/125159/4 "2008-01-07T22:33:30Z")

</div>

> Rails doesn’t have any of these controls, so repopulation is done in  
> whatever programmatic way you, as the developer want. It doesn’t  
> always make sense to repopulate controls – just in cases where there  
> has been, for example, an error in data entry. That means that for the  
> error cases, you typically spit back the fields that posted and  
> validated, and blank the rest (all of this is automatic if you follow  
> convention).
> 
> Is there any other compelling reason to use Viewstate on a [non-Asp.Net](http://non-Asp.Net)  
> app that I’m not aware of?

IIRC, Viewstate manages the current state of various server controls  
that don’t get replicated in HTML. For instance, the text value of a  
text field isn’t stored in viewstate, because it’s part of the POST  
request. But if you do something like change the color or size of a  
text field programmatically in a postback, that needs to be stored  
somewhere.

Rails will never have anything like this because this just isn’t the  
way we write our apps. Whether that’s good or bad is another  
discussion, but I’d implement a plugin if I wanted this functionality.

–  
Rick O.  
[http://lighthouseapp.com](http://lighthouseapp.com)  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
