# Text Field Value unless?

**URL:** <https://www.ruby-forum.com/t/text-field-value-unless/103412>\
**Category:** Rails\
**Created:** [May 5, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/text-field-value-unless/103412 "2007-05-05T16:37:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 5, 2007, 4:37pm UTC](https://www.ruby-forum.com/t/text-field-value-unless/103412/1 "2007-05-05T16:37:36Z")

</div>

Hello,

Why is this not working ☹

\<%= text\_field\_tag :post\_header, ‘’, :name =\> ‘post[header]’, :value  
@post.header if @post.header %\>

I want the default value to be @post.header if it’s not nil 🙂

Thanks 😃

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 5, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/text-field-value-unless/103412/2 "2007-05-05T19:21:10Z")

</div>

You can’t have an if statement embedded in a method like this. Not to  
mention you are missing the =\> operator. Try this:

\<%= text\_field\_tag :post\_header, ‘’, :name =\> ‘post[header]’, :value  
=\> @post.header ? @post.header : ‘’ %\>

On May 5, 8:37 am, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jamal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/35a633/32.png) [@jamal](https://www.ruby-forum.com/u/jamal)\
**Post date:** [May 5, 2007, 7:44pm UTC](https://www.ruby-forum.com/t/text-field-value-unless/103412/3 "2007-05-05T19:44:30Z")

</div>

dasil003 wrote:

> You can’t have an if statement embedded in a method like this. Not to  
> mention you are missing the =\> operator. Try this:
> 
> \<%= text\_field\_tag :post\_header, ‘’, :name =\> ‘post[header]’, :value  
> =\> @post.header ? @post.header : ‘’ %\>
> 
> On May 5, 8:37 am, Jamal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thanks,

It rocks 😃
