s c
2005-Sep-28 07:38 UTC
Question on combining 2 things to display text at once using collection_select
Hi everyone, I have a table projects and hours projects have field id, number, title and hours have project_id, id. I initiate a call: collection_select(:hour, :project_id, @projects, :id, :number) This works. Now I have difficulties if I want the display text be :number + :title instead of only :number as above.so I can write something like:(below doesn''t work) collection_select(:hour, :project_id, @projects, :id, :number+:title) Is there any way I can accompany this? Thank you. sammy --------------------------------- 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 雅虎助手-搜索、杀毒、防骚扰 _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Duane Johnson
2005-Oct-03 01:03 UTC
Re: Question on combining 2 things to display text at once using collection_select
The collection_select method is a shortcut method for the simple case where you have a collection of objects, each with two accessor methods, one for the ID and one for the display text. In more complex situations, you''ll either have to break down the select box in to a <select ... > tag and the options_from_collection_for_select, or else use the ''select'' helper method. The latter should work in your case: select(:hour, :project_id, @projects.collect {|p| [ p.number + p.title, p.id ] }, { :include_blank => true }) Duane Johnson (canadaduane) On Sep 28, 2005, at 12:38 AM, s c wrote:> Hi everyone, > I have a table projects and hours > projects have field id, number, title and hours have project_id, id. > > I initiate a call: > collection_select(:hour, :project_id, @projects, :id, :number) > > This works. Now I have difficulties if I want the display text be > :number + :title instead of only :number as above.so I can write > something like:(below doesn''t work) > collection_select(:hour, :project_id, @projects, :id, :number+:title) > > > Is there any way I can accompany this? > > Thank you. > sammy > > 雅虎免费G邮箱-中国第一绝无垃圾邮件骚扰超大邮箱 > 雅虎助手-搜索、杀毒、防骚扰 > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails