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: http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html. -- DeLynn Berry delynn@gmail.com http://www.delynnberry.com On 2/19/06, matthew collins <matthewcollins@cfl.rr.com> wrote:> 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? > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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? DeLynn Berry wrote:>Matthew, > >What you are looking for is the :prompt symbol: >http://api.rubyonrails.com/classes/ActionView/Helpers/FormOptionsHelper.html. > >-- >DeLynn Berry >delynn@gmail.com >http://www.delynnberry.com > >On 2/19/06, matthew collins <matthewcollins@cfl.rr.com> wrote: > > >>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? >> >> >>_______________________________________________ >>Rails mailing list >>Rails@lists.rubyonrails.org >>http://lists.rubyonrails.org/mailman/listinfo/rails >> >> >> >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >
> 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 Berry delynn@gmail.com http://www.delynnberry.com
strange indeed. <p><label for="project_type">Project Type</label><br /> <%= select(''project'', ''project_type_id'', @project_types.collect {|x| [x.name,x.id]}, {:prompt => "--Select One--"}) %></p> 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 DeLynn Berry wrote:>>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 Berry >delynn@gmail.com >http://www.delynnberry.com >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >
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 Berry delynn@gmail.com http://www.delynnberry.com
On Feb 19, 2006, at 1:53 PM, matthew collins wrote:> strange indeed. > > <p><label for="project_type">Project Type</label><br /> > <%= select(''project'', ''project_type_id'', @project_types.collect {| > x| [x.name,x.id]}, {:prompt => "--Select One--"}) %></p> > > and on the controller side, i have > > @project_types = ProjectType.find_all() > @project = Project.newCan 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 Perkins jperkins@sneer.org "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 <!--[form:project]--> <p><label for="project_type">Project Type</label><br /> <select id="project_project_type_id" name="project[project_type_id]"><option value="3">read</option> <option value="4">look</option> <option value="5">listen</option></select></p> and i''m running this in the test environment on the webrick server. Jason Perkins wrote:> > On Feb 19, 2006, at 1:53 PM, matthew collins wrote: > >> strange indeed. >> >> <p><label for="project_type">Project Type</label><br /> >> <%= select(''project'', ''project_type_id'', @project_types.collect {| >> x| [x.name,x.id]}, {:prompt => "--Select One--"}) %></p> >> >> 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 Perkins > jperkins@sneer.org > > "The computer allows you to make mistakes > faster than any other invention, with the > possible exception of handguns and tequila." > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
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.