# Problems with readonly attributes

**URL:** <https://www.ruby-forum.com/t/problems-with-readonly-attributes/172450>\
**Category:** Rails\
**Created:** [July 21, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/problems-with-readonly-attributes/172450 "2009-07-21T18:21:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [July 21, 2009, 6:21pm UTC](https://www.ruby-forum.com/t/problems-with-readonly-attributes/172450/1 "2009-07-21T18:21:00Z")

</div>

Hi all,

I have an editing form in which only one field must be editable;the  
other ones being readonly.Is there some way to automatize it,so I donÂ´t  
have to modify all fields by hand?

Thanks,  
Rafael R.

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [July 21, 2009, 7:51pm UTC](https://www.ruby-forum.com/t/problems-with-readonly-attributes/172450/2 "2009-07-21T19:51:08Z")

</div>

Rafael R. wrote:

> Hi all,
> 
> I have an editing form in which only one field must be editable;the  
> other ones being readonly.Is there some way to automatize it,so I donÂ´t  
> have to modify all fields by hand?
> 
> Thanks,  
> Rafael R.

why not disable that field in the form using javascript

and define few callback like before\_create that can set the value of  
that field to the default if field is subjected to modifications by  
turning off javascript in the browser or through any other techniques

---

<div class="post-metadata">

**Author:** ![rafaelrosafu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/59ef9b/32.png) [@rafaelrosafu](https://www.ruby-forum.com/u/rafaelrosafu)\
**Post date:** [July 21, 2009, 7:57pm UTC](https://www.ruby-forum.com/t/problems-with-readonly-attributes/172450/3 "2009-07-21T19:57:13Z")

</div>

On Jul 21, 1:51 pm, Virendra N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> why not disable that field in the form using javascript  
> No! That will fail – and leave the field editable – if JavaScript  
> is turned off.

In general, there is almost never a good reason to use a read-only  
field. If the data is not editable, just put it on the page as plain  
text.

If there’s some other issue, please explain in more detail.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
