[Rails] Ajax request
Hi
I'm trying to create an Ajax request that displays a list of inventory
items resulting from a search on a keyword. How can I insert the list
of inventory items using a partial or a string of html onto the page
following the ajax request? The following doesn't work because I
can't use a content_tag helper method in a controller.
I guess another question would be why doesn't the inventories div
update and show the inventory items after the ajax request?
I have this in my controller (this uses a string of html)
def find_by_keyword
@inventories = Inventory.find(:all, :conditions => ['inventory_id
LIKE ?', params[:inventory][:keyword]])
@inventories_list = @inventories.map { |inventory|
content_tag("li", inventory['id'])}
render :inline => @inventories_list
end
And this in the view:
<% form_remote_tag :url => { :controller =>
"purchase_orders", :action => "find_by_keyword" }, :update=>
"inventories" do |f| -%>
<%= model_auto_completer('inventory[keyword]', '',
'inventory[inventory_id]', '', {:method => :get})%>
<%= submit_tag "Find!" %>
<% end %>
<div id = "inventories">
<% if !@inventories.nil?%>
<% for inventory in @inventories %>
<% link_to inventory['id'], :controller =>
"purchase_orders", :action => "new", :inventory_id => inventory['id']
%>
<% end %>
<% end %>
</div>
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home