Select, first option empty value?

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?

Matthew,

What you are looking for is the :prompt symbol:
Peak Obsession.


DeLynn B.
[email protected]

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?

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

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.
[email protected]

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.
[email protected]

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.
[email protected]

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

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.

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.