Hello. I want to select an item from a select list and have that
result in an ajax call that updates two sections on the page. Here is
the code in the controller
def create
…
render :update do |page|
page.replace_html ‘list_items’, :partial => ‘lists/list_items’
page.replace_html ‘add_item’, :partial => ‘lists/add_item’
end
end
Here is the version of code in the template that I WANT to use to
POST to this action:
<%= form_remote_tag :html => { :action => url_for(:controller =>
“list_item_links”, :action => “create”) }, :eval_scripts => true %>
<%= hidden_field ‘list_item_link’, ‘list_id’, :value => @list.id%>
<%= hidden_field ‘list_item_link’, ‘list_item_type’, :value => ‘List’ %>
Which list?
<%= select ‘list_item_link’, ‘list_item_id’, @lists.collect{ |l|
[ l.name, l.id] },
{ :include_blank => true},
{ :class => “formfield”, :onchange => “this.form.submit()” }
%>
<%= end_form_tag %>
And here is the code in the template that actually works (using a GET
instead):
Which list?
<%= select ‘list_item_link’, ‘list_item_id’, @lists.collect{ |l|
[ l.name, l.id] },
{ :include_blank => true},
{ :class => “formfield”, :onchange => “new
Ajax.Request(’/admin/list_item_links/create?list_item_link
[list_item_type]=List&list_item_link[list_id]=#{@list.id}
&list_item_link[list_item_id]=’ +
this.options[selectedIndex].value,{asynchronous:true,
evalScripts:true}); return false;” }
%>
The first example, using the form, results in javascript being
rendered in the browser rather than being executed. Note that it does
say “:eval_scripts => true” and that the resulting javascript does
include “evalScripts:true”.
I’m using rails 1.1.2.
Thanks in advance,
David