i have a selectlist with employees, how can i insert at the top a option
"All" except of the blank one.
and the selected option must be selected on the next page, so i can see what
i have selected.
rhtml
<tr>
<td><label
for="employee_id">Employee</label></td>
<td colspan="3"><%= select "employee",
"id", @employees.collect {|e|
[e.last_name + " " + e.first_name,e.id]}, { :include_blank => true
} %></td>
</tr>
controller
@employees = Employee.find_all_by_firm_id(firm_id, :order =>"last_name
ASC")
@employee_id = params[:employee][:id].blank? ? '''' :
params[:employee][:id]
@time_entries = TimeEntry.find(:all, :conditions
=>["time_entries.firm_id =
? AND employee_id like ? ", firm_id, "%#{@employee_id}%, :order =>
"time_entries.start_time DESC", :include=>[:employee,:geotag])
I just ran into this problem when building a simple search form. Heres what
I came up with... (not the most elegant, so I''m also interested in a
better
way):
<select name="product">
<%= options_for_select [''All''] + @all_categories.collect{
|category|
category.name <http://category.name> }.sort, @params[:product] %>
</select>
Adam
On 9/28/05, Nick Brutyn
<brutyn_nick-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:>
> i have a selectlist with employees, how can i insert at the top a option
> "All" except of the blank one.
> and the selected option must be selected on the next page, so i can see
> what
> i have selected.
>
> rhtml
>
> <tr>
> <td><label
for="employee_id">Employee</label></td>
> <td colspan="3"><%= select "employee",
"id", @employees.collect {|e|
> [e.last_name + " " + e.first_name,e.id <http://e.id>]}, {
:include_blank
> => true } %></td>
> </tr>
>
>
> controller
>
> @employees = Employee.find_all_by_firm_id(firm_id, :order
=>"last_name
> ASC")
> @employee_id = params[:employee][:id].blank? ? '''' :
params[:employee][:id]
>
> @time_entries = TimeEntry.find(:all, :conditions
=>["time_entries.firm_id
> > ? AND employee_id like ? ", firm_id, "%#{@employee_id}%,
:order =>
> "time_entries.start_time DESC", :include=>[:employee,:geotag])
>
>
> _______________________________________________
> 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
One way would be to change your select tag to look like this:
<%= select "employee", "id", @employee_options, {
:include_blank => true } %>
..and then put this in your controller:
@employee_options = [["All","The_Value_For_All"]] +
@employees.collect {|e|> [e.last_name + " " + e.first_name,e.id]}
--Wilson.
On 9/28/05, Nick Brutyn
<brutyn_nick-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org>
wrote:> i have a selectlist with employees, how can i insert at the top a option
> "All" except of the blank one.
> and the selected option must be selected on the next page, so i can see
what
> i have selected.
>
> rhtml
>
> <tr>
> <td><label
for="employee_id">Employee</label></td>
> <td colspan="3"><%= select "employee",
"id", @employees.collect {|e|
> [e.last_name + " " + e.first_name,e.id]}, { :include_blank =>
true } %></td>
> </tr>
>
>
> controller
>
> @employees = Employee.find_all_by_firm_id(firm_id, :order
=>"last_name ASC")
> @employee_id = params[:employee][:id].blank? ? '''' :
params[:employee][:id]
>
> @time_entries = TimeEntry.find(:all, :conditions
=>["time_entries.firm_id > ? AND employee_id like ? ", firm_id,
"%#{@employee_id}%, :order =>
> "time_entries.start_time DESC", :include=>[:employee,:geotag])
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>