# Select\_tag help

**URL:** <https://www.ruby-forum.com/t/select-tag-help/144188>\
**Category:** Rails\
**Created:** [July 26, 2008, 11:47am UTC](https://www.ruby-forum.com/t/select-tag-help/144188 "2008-07-26T11:47:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [July 26, 2008, 11:47am UTC](https://www.ruby-forum.com/t/select-tag-help/144188/1 "2008-07-26T11:47:04Z")

</div>

Hi All,

controller:

def html  
@tag1=[“Arun”,“Babu”,Chitra"]  
end

html.html.erb :

\<%= select\_tag  
“@tag1”,"#{@tag1[0]}#{@tag1[1]}  
"%\>

It was working fine. But my question is any other simple ways are  
available. Because i have array in controller, but using individually in  
view…

Awaiting your reply

Thanks  
P.Raveendran

> **[Raveendran](https://raveendran.wordpress.com)**
>
> Nothing is impossible...

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [July 26, 2008, 12:03pm UTC](https://www.ruby-forum.com/t/select-tag-help/144188/2 "2008-07-26T12:03:20Z")

</div>

Hi All,

i herewith written my final working code…

controller:

def htmlhelp  
@tag=[“a”,“b”,“c”,“d”]  
@collection=[]

```
@tag.each do |value|
  value="<option>"+value+"</option>"
  @collection << value
  end

```

end

View:

\<%= select\_tag “@tag12”, @collection.to\_s %\>

Any other short ways…?

Regards,  
P.Raveendran  
http:raveendra.wordpress.com

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [July 26, 2008, 3:00pm UTC](https://www.ruby-forum.com/t/select-tag-help/144188/3 "2008-07-26T15:00:26Z")

</div>

On Sat, Jul 26, 2008 at 3:03 AM, Raveendran J.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @tag.each do |value|  
> value=“”+value+“”  
> @collection \<\< value  
> end  
> end
> 
> View:
> 
> \<%= select\_tag “@tag12”, @collection.to\_s %\>

you can try  
\<%= select\_tag @tag12, options\_for\_select( @tag )

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [July 26, 2008, 3:54pm UTC](https://www.ruby-forum.com/t/select-tag-help/144188/4 "2008-07-26T15:54:17Z")

</div>

Raveendran J. wrote:

> > \<%= select\_tag @tag12, options\_for\_select( @tag )

> Hi Laskar,

> Thanks a lot for ur quick and beautiful code help.

Now try this one.

The @yo object has a list of ids from the a model called Mod.

We need this to make the ids sticky in the form:

form\_for :yo do |f|

f.collection\_select(:ids, Mod.find(:all), :id, :name)

The problem is, even after we make all that pseudo-Rails into real Rails  
code,  
with all the right arguments, the ids are not sticky.

(Sticky means if you serve the page twice with the same @yo object, the  
same Mod  
items should still be selected.)

Any ideas? We had to go back to select\_tag, and generally do for  
ourselves  
everything f.collection\_select was supposed to do.

–  
Phlip

---

<div class="post-metadata">

**Author:** ![jazzezravi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/71e660/32.png) [@jazzezravi](https://www.ruby-forum.com/u/jazzezravi)\
**Post date:** [July 26, 2008, 3:04pm UTC](https://www.ruby-forum.com/t/select-tag-help/144188/5 "2008-07-26T15:04:28Z")

</div>

Gabriel L. wrote:

> you can try  
> \<%= select\_tag @tag12, options\_for\_select( @tag )
> 
> –  
> Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Hi Laskar,

Thanks a lot for ur quick and beautiful code help.

Regards,  
P.Raveendran

> **[Raveendran](https://raveendran.wordpress.com)**
>
> Nothing is impossible...
