# Select, first option empty value?

**URL:** <https://www.ruby-forum.com/t/select-first-option-empty-value/70525>\
**Category:** Rails\
**Created:** [February 19, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525 "2006-02-19T18:11:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/1 "2006-02-19T18:11:37Z")

</div>

using the below:

\<%= select(‘project’, ‘project\_type\_id’, @project\_types.collect {|x|  
[x.name,x.id]}, {:include\_blank =\> true}) %\>

but i’d like that first option to have something like “select project  
type” with an empty value?

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 6:23pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/2 "2006-02-19T18:23:45Z")

</div>

Matthew,

What you are looking for is the :prompt symbol:  
[Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html).

–  
DeLynn B.  
removed\_email\_address@domain.invalid

> **[DeLynn Berry](https://delynnberry.com/)**

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/3 "2006-02-19T19:24:40Z")

</div>

my apologies, i guess i’m just not getting the syntax down.

i’m trying

\<%= select(‘project’, ‘project\_type\_id’, @project\_types.collect {|x|  
[x.name,x.id]}, {:prompt =\> “pick something”}) %\>

and it’s not showing up?

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 8:55pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/4 "2006-02-19T20:55:40Z")

</div>

strange indeed.

Project Type  
\<%= select('project', 'project\_type\_id', @project\_types.collect {|x| [x.name,x.id]}, {:prompt =\> "--Select One--"}) %\>

and on the controller side, i have

@project\_types = ProjectType.find\_all()  
@project = Project.new

ruby -v = 1.8.2  
rails -v = 1.0.0

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/5 "2006-02-19T20:22:11Z")

</div>

> and it’s not showing up?

Hmm, that’s strange. It looks fine to me. Here’s a snippet from my  
application that is working:  
\<%= select(“user”, “id”, @users.collect {|u| [u.name, u.id]}, {:prompt  
=\> “–Select One–”}) %\>

–  
DeLynn B.  
removed\_email\_address@domain.invalid

> **[DeLynn Berry](https://delynnberry.com/)**

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 9:10pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/6 "2006-02-19T21:10:52Z")

</div>

Hmmm, very interesting. I copied your code snippet directly into my  
app and just changed the @project\_types to @users and it worked just  
fine. Could I see the generated HTML by chance?

Is there an item that is being selected? Is it just the first item in  
the list or is it something else? Does your Project object have a  
default project type perhaps? What happens if you comment out the  
“@project = Project.new” bit in your contoller?

–  
DeLynn B.  
removed\_email\_address@domain.invalid

> **[DeLynn Berry](https://delynnberry.com/)**

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 9:25pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/7 "2006-02-19T21:25:59Z")

</div>

On Feb 19, 2006, at 1:53 PM, matthew collins wrote:

> strange indeed.
> 
> Project Type  
> \<%= select('project', 'project\_type\_id', @project\_types.collect {| x| [x.name,x.id]}, {:prompt =\> "--Select One--"}) %\>
> 
> and on the controller side, i have
> 
> @project\_types = ProjectType.find\_all()  
> @project = Project.new

Can you run script/console and then do:

@project\_types = ProjectType.find\_all()

to see what’s returned? Alternatively, you can do:

debug(@project\_types) in the view to see what it’s set to. But the  
console is going to let you explore further.

–  
Jason P.  
removed\_email\_address@domain.invalid

“The computer allows you to make mistakes  
faster than any other invention, with the  
possible exception of handguns and tequila.”

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 10:20pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/8 "2006-02-19T22:20:20Z")

</div>

script/console:  
@project\_types = ProjectType.find\_all()  
=\> [#\<ProjectType:0xb7798a04 @attributes={“name”=\>“read”, “id”=\>“3”}\>,  
#\<ProjectType:0xb77989c8 @attributes={“name”=\>“look”, “id”=\>“4”}\>,  
#\<ProjectType:0xb779898c @attributes={“name”=\>“listen”, “id”=\>“5”}\>]

debug(@project\_types)

* * *

- !ruby/object:ProjectType  
attributes:  
name: read  
id: “3”
- !ruby/object:ProjectType  
attributes:  
name: look  
id: “4”
- !ruby/object:ProjectType  
attributes:  
name: listen  
id: “5”

and, from another request, the generated html

Project Type  
read look listen

and i’m running this in the test environment on the webrick server.

---

<div class="post-metadata">

**Author:** ![matthew\_collins](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e79b87/32.png) [@matthew\_collins](https://www.ruby-forum.com/u/matthew_collins)\
**Post date:** [February 19, 2006, 11:20pm UTC](https://www.ruby-forum.com/t/select-first-option-empty-value/70525/9 "2006-02-19T23:20:50Z")

</div>

matthew collins wrote:

> my apologies, i guess i’m just not getting the syntax down.
> 
> i’m trying
> 
> \<%= select(‘project’, ‘project\_type\_id’, @project\_types.collect {|x|  
> [x.name,x.id]}, {:prompt =\> “pick something”}) %\>
> 
> and it’s not showing up?

I think :prompt only works if project\_type\_id is defined “default null”  
(and not “not null”) in the database projects table.

–  
We develop, watch us RoR, in numbers too big to ignore.
