Brian,
I had to change your code here and there to make it work, but I finally
managed. Thank you for putting me on the right track!
To help other newbies, here follows the final code:
In the view:
<% remote_function :url => {:action => ‘get_sales_order_details’} %>
<%= collection_select(:salesorder, :ordernr, Salesorder.find(:all),
:ordernr, :ordernr, {:prompt => “– Select an order number –”}, {:id
=> ‘ordernr_selected’}) %>
<%= observe_field ‘ordernr_selected’,
:url => {:action => ‘get_sales_order_details’},
:with => ‘ordernr’ %>
And in the controller:
def get_sales_order_details
@salesorder = Salesorder.find_by_ordernr(params[:ordernr])
render :update do |page|
page.replace_html “order_details”, :partial =>
‘sales_order_details’
end
end
Note that I use ‘find_by_ordernr(params[:ordernr])’ i.s.o.
‘find(params[:id])’, since I don’t have the :id field in my table. The
primary key here is the ordernr.
Brian P. wrote:
You can do this by calling remote function and using the observe_field
helper w/out specifying frequency (forces it to use onChange event):
i.e.
<% remote_function :url => {:action => ‘get_sales_order_details’} %>
<%= collection_select :salesorder, :ordernr, Salesorder.find(:all),
:ordernr, :ordernr, {:prompt => “– Select an order number –”}, {} %>
<% observe_field :ordernr,
:url => {:action => ‘get_sales_order_details’},
:with => :ordernr %>
In your controller you want define the get_sales_order_details
function…
def get_sales_order_details
@sales_order = SalesOrders.find(params[:id])
render :update do |page|
page.replace_html “order_details”, :partial => ‘sales_order_details’
end
end
…where “order_details” is the section of code in your main form (using
<div id="order_details></div> tags) to be replace with the partial
(which I called 'sales_order_details').
<p>Hope this helps.</p>
</blockquote>