Paul Davis
2005-Aug-16 08:56 UTC
(Newbie) Connect a selection list with a controller method
I have many pages of news items that I''m displaying in the
newsitem/list
method, and I want to filter them by source.
At the top of one of the columns "source" I have a selection list with
the source names.
The selection list gets built just fine using:
<th>
<% sources = Source.find(:all, :order => "name")
sources[0].name = ''Select Source'' %>
<%= collection_select("source", "id", sources, :id,
:name) %>
</th>
I have a method, that also works, that I want to call like:
"newsitem/list_for_source/23" where 23 is the id of the source chosen
in
the list.
I''ve tried putting "observe_field" like:
<%= observe_field(
"source_id",
:url=>{
:controller => ''macroitem'',
:action => ''list_by_source'',
:id => [What goes here?]
}
)
%>
but this never gets triggered at all by a change in the selection.
How do I trigger a re-load with this URL, and pass the id of the
currently elected item to the URL?
???
Kevin Fullerton
2005-Aug-16 10:12 UTC
Re: (Newbie) Connect a selection list with a controller method
Try adding :frequency => 0.5 to your observe_field after the } for :url
so it reads
<%= observe_field(
"source_id",
:url=>{
:controller => ''macroitem'',
:action => ''list_by_source'',
:id => [What goes here?]
},
:frequency => 0.5
)
%>
Cheers
Kevin
On Tue, Aug 16, 2005 at 08:56:58AM +0000, Paul Davis
wrote:> I have many pages of news items that I''m displaying in the
newsitem/list
> method, and I want to filter them by source.
>
> At the top of one of the columns "source" I have a selection list
with
> the source names.
>
> The selection list gets built just fine using:
> <th>
> <% sources = Source.find(:all, :order => "name")
> sources[0].name = ''Select Source'' %>
> <%= collection_select("source", "id", sources,
:id, :name) %>
> </th>
>
> I have a method, that also works, that I want to call like:
> "newsitem/list_for_source/23" where 23 is the id of the source
chosen in
> the list.
>
> I''ve tried putting "observe_field" like:
>
> <%= observe_field(
> "source_id",
> :url=>{
> :controller => ''macroitem'',
> :action => ''list_by_source'',
> :id => [What goes here?]
> }
> )
> %>
>
> but this never gets triggered at all by a change in the selection.
>
> How do I trigger a re-load with this URL, and pass the id of the
> currently elected item to the URL?
>
> ???
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails