# Conditional :value in text\_field?

**URL:** <https://www.ruby-forum.com/t/conditional-value-in-text-field/79891>\
**Category:** Rails\
**Created:** [December 20, 2006, 12:18pm UTC](https://www.ruby-forum.com/t/conditional-value-in-text-field/79891 "2006-12-20T12:18:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [December 20, 2006, 12:18pm UTC](https://www.ruby-forum.com/t/conditional-value-in-text-field/79891/1 "2006-12-20T12:18:39Z")

</div>

Languages \<%= text\_field 'person', 'languages', {:value =\> "English" } %\>

I only want to send the value of “English” if @person.languages.empty?  
Rails doesn’t like my attempts so far. Has anyone been able to do this?

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [December 20, 2006, 8:25pm UTC](https://www.ruby-forum.com/t/conditional-value-in-text-field/79891/2 "2006-12-20T20:25:32Z")

</div>

Have you tried this?

Languages \<%= if @person.languages.empty? text\_field 'person', 'languages', {:value =\> "English" } else text\_field 'person', 'languages' end %\>

Hope that helps,  
Matt Buck

---

<div class="post-metadata">

**Author:** ![taylorstrait](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/b5a626/32.png) [@taylorstrait](https://www.ruby-forum.com/u/taylorstrait)\
**Post date:** [December 20, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/conditional-value-in-text-field/79891/3 "2006-12-20T22:04:00Z")

</div>

Thanks, Matt. I ended up using this to deal with absent variables in  
new users while preserving user attributes in edits:

Languages \<%= if @person.languages && !@person.languages.empty? text\_field 'person', 'languages' else text\_field 'person', 'languages', {:value =\> "English" } end %\>
