Hi, I need to pass variable in the search form to an AJAX partial but it doesn''t work. please tell me how to pass @groceries to the partial. {{FORM}} <% form_remote_tag :url => {:action => :search}, :method => "get" do %> <label for="item_name"></label> <%= text_field_tag("query", params[''query''], :size => 20 ) %> <%= submit_tag "Search" %> {{CONTROLLER}} def search groceries_per_page = 4 @groceries = Groceries.search params[:query], {:page => params[:page], :per_page => groceries_per_page} respond_to do |format| format.js end if request.xml_http_request? render :partial => "search", :layout => false end end {{PARTIAL}} <% if @groceries == nil %> @groceries is nil <% else %> <% for groceries in @groceries %> groceries.name <% end %> {{search.js.rjs}} page.replace_html("sgreplace", :partial => "search" ) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
<% if @groceries == nil %> @groceries is nil <% else %> <% for groceries in @groceries %> <%= groceries.name %> <% end %> should work --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
oops should be <%= @groceries.name %> of course --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The partial is not my problem because I get the return on the ajax as @groceries is nil which means it cannot pass through the first if statement. Which also means that @groceries is not being passed to the partial through AJAX -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Thorsten Müller Sent: Monday, August 25, 2008 10:45 PM To: Ruby on Rails: Talk Subject: [Rails] Re: Passing instance through AJAX oops should be <%= @groceries.name %> of course --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
> I need to pass variable in the search form to an AJAX partial but it > doesn''t work. please tell me how to pass @groceries to the partial....was the question :) ok, then your query fails.> @groceries = Groceries.search params[:query], {:page => > params[:page], :per_page => groceries_per_page}return nil. that''s nothing to do with the partial. The query looks a bit strange. 1) It should be Grocery not Groceries (and this should give you an error) 2) It should be find, not search. Are you using any plugin like ferret for the search? Then you should mention that. Does params[:query] have a value? Does it search anything at all? My guess: @groceries is nil all the time, because the query fails... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Its not the query because without ajax it works. The groceries is correct and the reason why it is search is because I am using thinking sphinx not find for my searching in the app. -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Thorsten Müller Sent: Monday, August 25, 2008 11:41 PM To: Ruby on Rails: Talk Subject: [Rails] Re: Passing instance through AJAX> I need to pass variable in the search form to an AJAX partial but it > doesn''t work. please tell me how to pass @groceries to the partial....was the question :) ok, then your query fails.> @groceries = Groceries.search params[:query], {:page => > params[:page], :per_page => groceries_per_page}return nil. that''s nothing to do with the partial. The query looks a bit strange. 1) It should be Grocery not Groceries (and this should give you an error) 2) It should be find, not search. Are you using any plugin like ferret for the search? Then you should mention that. Does params[:query] have a value? Does it search anything at all? My guess: @groceries is nil all the time, because the query fails... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---
When I do <%= params[:query] %> in the partial it shows my query which is red. This is really weird everthing but the instance is passing through. Thinking sphinx anomally? -----Original Message----- From: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Thorsten Müller Sent: Monday, August 25, 2008 11:41 PM To: Ruby on Rails: Talk Subject: [Rails] Re: Passing instance through AJAX> I need to pass variable in the search form to an AJAX partial but it > doesn''t work. please tell me how to pass @groceries to the partial....was the question :) ok, then your query fails.> @groceries = Groceries.search params[:query], {:page => > params[:page], :per_page => groceries_per_page}return nil. that''s nothing to do with the partial. The query looks a bit strange. 1) It should be Grocery not Groceries (and this should give you an error) 2) It should be find, not search. Are you using any plugin like ferret for the search? Then you should mention that. Does params[:query] have a value? Does it search anything at all? My guess: @groceries is nil all the time, because the query fails... --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org 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 -~----------~----~----~----~------~----~------~--~---