# Setting the selected value in select helper

**URL:** <https://www.ruby-forum.com/t/setting-the-selected-value-in-select-helper/141814>\
**Category:** Rails\
**Created:** [June 30, 2008, 7:49pm UTC](https://www.ruby-forum.com/t/setting-the-selected-value-in-select-helper/141814 "2008-06-30T19:49:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [June 30, 2008, 7:49pm UTC](https://www.ruby-forum.com/t/setting-the-selected-value-in-select-helper/141814/1 "2008-06-30T19:49:17Z")

</div>

I have the follwoing select in my view

\<%= select(‘role’, ‘name’, Role::DEFAULT\_COMPANY\_NAMES, { :prompt =\>  
l(:select\_a\_role) }, {:style =\> ‘width:150px;’}) %\>

\<%= select(‘role’, ‘company\_id’, @company\_choices, { :prompt =\>  
l(:select\_a\_company) }, {:style =\> ‘width:200px;’}) %\>

on first display I have the prompt, Ok  
but when the user forget to select one of 2 seeltions, I would like  
to redisplay the already selected one…

I tried  
@role\_name = params[:role][:name]  
@role\_company\_id = params[:role][:company\_id]  
before redisplay but no pre-selctiuon is being made ( because of the  
prompt… ??)

thanks

erwin

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [June 30, 2008, 10:23pm UTC](https://www.ruby-forum.com/t/setting-the-selected-value-in-select-helper/141814/2 "2008-06-30T22:23:18Z")

</div>

this works on your model.  
so you need something like  
@role = Role.new(:name =\> params[:role][:name], :company\_id =\>  
params[:role][:company\_id])

---

<div class="post-metadata">

**Author:** ![kadoudal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f0a364/32.png) [@kadoudal](https://www.ruby-forum.com/u/kadoudal)\
**Post date:** [July 1, 2008, 12:03am UTC](https://www.ruby-forum.com/t/setting-the-selected-value-in-select-helper/141814/3 "2008-07-01T00:03:24Z")

</div>

On 30 juin, 22:22, Thorsten Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> this works on your model.  
> so you need something like  
> @role = Role.new(:name =\> params[:role][:name], :company\_id =\>  
> params[:role][:company\_id])

yes … I see , need to eliminate the prompt…

thanks
