# Select helper still the worth thing in rails

**URL:** <https://www.ruby-forum.com/t/select-helper-still-the-worth-thing-in-rails/142543>\
**Category:** Rails\
**Created:** [July 9, 2008, 1:26am UTC](https://www.ruby-forum.com/t/select-helper-still-the-worth-thing-in-rails/142543 "2008-07-09T01:26:02Z")\
**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:** [July 9, 2008, 1:26am UTC](https://www.ruby-forum.com/t/select-helper-still-the-worth-thing-in-rails/142543/1 "2008-07-09T01:26:02Z")

</div>

I have been trying all the day to make it happen, initial display is  
fine , but I cannot redisplay the selected value once the choice is  
done in my select helper

I setup my slector in a helper (need to include the first option  
‘all’, as a prompt is displayed only once…  
in my partial  
def company\_role\_selection(selection=nil)  
roles= [[‘all’, 0]]  
roles += company\_roles.collect {|h| [ h.name,  
company\_roles.index(h)]}.compact.uniq  
select(‘role’, ‘id’, roles, {:selected =\> selection} ,{:onchange  
=\> “$(‘select\_role’).submit()”})  
end

in my controller, I get the selection  
@selection = params[:role][:id]

then I find and display the users…

and I redisplay the page with the form and the list

\<% form\_for(:user, :url =\> user\_path(@user), :html =\> {:method  
=\> :get, :id =\> ‘select\_role’ }) do |f| %\>  
\<%= render :partial =\> ‘select\_role’ , :locals=\>{:selection =\>  
@selection } -%\>  
\<% end %\>

 \<%= render :partial =\> 'index' -%\>

---

<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 9, 2008, 11:33am UTC](https://www.ruby-forum.com/t/select-helper-still-the-worth-thing-in-rails/142543/2 "2008-07-09T11:33:29Z")

</div>

On Jul 9, 12:14 am, Erwin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in my controller, I get the selection  
> @selection = params[:role][:id]

You probably need to convert that to an integer (since ‘1’ != 1)

Fred

---

<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 9, 2008, 3:46pm UTC](https://www.ruby-forum.com/t/select-helper-still-the-worth-thing-in-rails/142543/3 "2008-07-09T15:46:59Z")

</div>

On 9 juil, 11:30, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Jul 9, 12:14 am, Erwin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > in my controller, I get the selection  
> > @selection = params[:role][:id]
> 
> You probably need to convert that to an integer (since ‘1’ != 1)
> 
> Fred
> 
> >

got it… that’s the point !! could not remember it… thanks a lot
