Hi, I''ve got a live_search field in a partial that is on several different pages. On all pages, except 1, it works fine. On the page it doesn''t work on, it seems it never executes it action. Here''s my observe_field code inside the partial: <h1><label for="searchtext">Live Search:</label></h1> <%= text_field_tag :searchtext %> <%= observe_field(:searchtext, :frequency => 0.5, :update => :search_hits, :url => { :action => :live_search }, :loading => "Element.show(''search-indicator'')", :loaded => "Element.hide(''search-indicator'')", :with => "''q='' + escape($F(''searchtext''))")%> <%= image_tag("indicator.gif", :id => ''search-indicator'', :style => ''display:none'') %> <div id="search_hits"></div> Here is my action (inside application.rb) def live_search @search = @params[:q] @results = Product.sql_for_search_results(@search) render(:partial => "partials/search_layout", :layout => false) end If I put a breakpoint in live_search, it never gets tripped by the observe_field on the one problem page. The problem page tries to re-render itself inside the update div. It happens in both firefox and IE6. I''m not sure how else to troubleshoot this. Any suggestions? Thanks, Steve http://www.smarkets.net -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060209/974c3cef/attachment.html
Steve Odom wrote:> I''ve got a live_search field in a partial that is on several different > pages. On all pages, except 1, it works fine. On the page it doesn''t > work on, it seems it never executes it action. > > Here''s my observe_field code inside the partial: > > <h1><label for="searchtext">Live Search:</label></h1> > <%= text_field_tag :searchtext %> > <%= observe_field(:searchtext, > :frequency => 0.5, > :update => :search_hits, > :url => { :action => :live_search }, > :loading => "Element.show(''search-indicator'')", > :loaded => " Element.hide(''search-indicator'')", > :with => "''q='' + escape($F(''searchtext''))")%> > <%= image_tag("indicator.gif", > :id => ''search-indicator'', > :style => ''display:none'') %> > <div id="search_hits"></div> > ... > If I put a breakpoint in live_search, it never gets tripped by the > observe_field on the one problem page. > > The problem page tries to re-render itself inside the update div.It looks like your :url parameter is actually being set to an empty hash, which you can verify by looking at the HTML source and seeing that the path in the Ajax call is that of the rendered page itself. If you have accurately copied you code into your post the only thing I can think of is that you are using an earlier version of Rails for which hash values for urls must be strings rather than symbols. Try :url => { :action => ''live_search'' } -- We develop, watch us RoR, in numbers too big to ignore.
Thanks Mark. I''m using 1.0. I tried changing my :action from :live_search to ''live_search'' to no avail. Here is what the html source looks like for a page that works and the problem page: Works: <script type="text/javascript"> //<![CDATA[ new Form.Element.Observer(''searchtext'', 0.5, function(element, value) {new Ajax.Updater(''search_hits'', ''/landing/live_search'', {asynchronous:true, evalScripts:true, onLoaded:function(request){Element.hide(''search-indicator'')}, onLoading:function(request){Element.show(''search-indicator'')}, parameters:''q='' + escape($F(''searchtext''))})}) //]]> </script> Does not work: <script type="text/javascript"> //<![CDATA[ new Form.Element.Observer(''searchtext'', 0.5, function(element, value) {new Ajax.Updater(''search_hits'', ''/portfolio/live_search'', {asynchronous:true, evalScripts:true, onLoaded:function(request){Element.hide(''search-indicator'')}, onLoading:function(request){Element.show(''search-indicator'')}, parameters:''q='' + escape($F(''searchtext''))})}) //]]> Just to be clear, my live_search method is not in my landing controller, but rather in application.rb, so it should be available to both. Curious. Steve http://www.smarkets.net </script> On 2/9/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Steve Odom wrote: > > > I''ve got a live_search field in a partial that is on several different > > pages. On all pages, except 1, it works fine. On the page it doesn''t > > work on, it seems it never executes it action. > > > > Here''s my observe_field code inside the partial: > > > > <h1><label for="searchtext">Live Search:</label></h1> > > <%= text_field_tag :searchtext %> > > <%= observe_field(:searchtext, > > :frequency => 0.5, > > :update => :search_hits, > > :url => { :action => :live_search }, > > :loading => "Element.show(''search-indicator'')", > > :loaded => " Element.hide(''search-indicator'')", > > :with => "''q='' + escape($F(''searchtext''))")%> > > <%= image_tag("indicator.gif", > > :id => ''search-indicator'', > > :style => ''display:none'') %> > > <div id="search_hits"></div> > > ... > > If I put a breakpoint in live_search, it never gets tripped by the > > observe_field on the one problem page. > > > > The problem page tries to re-render itself inside the update div. > > It looks like your :url parameter is actually being set to an empty > hash, which you can verify by looking at the HTML source and seeing > that the path in the Ajax call is that of the rendered page itself. > > If you have accurately copied you code into your post the > only thing I can think of is that you are using an earlier version > of Rails for which hash values for urls must be strings rather than > symbols. Try :url => { :action => ''live_search'' } > > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060209/93e43636/attachment.html
Steve Odom wrote:> Thanks Mark. I''m using 1.0. I tried changing my :action from > :live_search to ''live_search'' to no avail. > > Just to be clear, my live_search method is not in my landing controller, but rather in > application.rb, > so it should be available to both. > > Curious.Yes. The url in the Ajax call is correct. What do you see in your Rails log when the request is sent? Does copying the live_search method into your Portfolio controller make it work? -- We develop, watch us RoR, in numbers too big to ignore.
Copying live_search method into my portfolio controller doesn''t help. Here are two log examples: WORKS: (in landing_controller) ------------------------ Processing LandingController#live_search (for 127.0.0.1 at 2006-02-10 11:37:29) [POST] Parameters: {"action"=>"live_search", "q"=>"pau", "controller"=>"landing"} [4;36;1mProduct Load (0.250000) [0;1mSELECT p.id, p.product FROM products p WHERE lower(p.prdMFG) LIKE ''%pau%'' OR lower(p.product) LIKE ''%pau%'' OR lower(p.asin) LIKE ''%pau%'' AND p.active = 1 LIMIT 20 [4;35;1mProduct Columns (0.480000) SHOW FIELDS FROM products Rendered partials/_search_results (1.03000) ------------------------- FAILS: (in portfolio_controller) --------------------------- Processing PortfolioController#index (for 127.0.0.1 at 2006-02-10 11:39:09) [POST] Parameters: {"action"=>"index", "id"=>"live_search", "q"=>"pau", "controller"=>"portfolio"} [4;35;1mUser Load (0.040000) SELECT * FROM users WHERE (users.`login` = ''live_search'' ) LIMIT 1 Attempt to access portfolio without a login id Redirected to http://127.0.0.1:3000/ ------------------------------ It seems like what is happening is it is re-executing the code in my index method in the portfolio controller. That method looks like this: def index store_location @uid = 0 @uid = @session[:user].id if user_logged_in? @tid = User.find_by_login(@params[:id]) @pageTitle = "#{@tid.login}''s Portfolio" @cash = Trade.find_by_user_id(@tid.id, :order => "updated_on DESC", :limit => 1) @list = Trade.myportfolio(@tid.id) rescue logger.error("Attempt to access portfolio without a login id") flash[:notice] = ''Sorry, I could not find that page'' redirect_to(home_url) end It is re-executing the @tid = User.find_by_login code. What could cause that? I do have a custom route for this /portfolio/index page: map.portfolio ''portfolio/:id'', :controller => ''portfolio'', :action => ''index'' I don''t know if that is involved in this. Any suggestions are appreciated. Thanks, Steve http://www.smarkets.net On 2/10/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Steve Odom wrote: > > Thanks Mark. I''m using 1.0. I tried changing my :action from > > :live_search to ''live_search'' to no avail. > > > > Just to be clear, my live_search method is not in my landing controller, > but rather in > > application.rb, > > so it should be available to both. > > > > Curious. > > Yes. The url in the Ajax call is correct. What do you see in your > Rails log when the request is sent? Does copying the live_search > method into your Portfolio controller make it work? > > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060210/03615fcc/attachment-0001.html
Steve Odom wrote:> Parameters: {"action"=>"index", "id"=>"live_search", "q"=>"pau", > "controller"=>"portfolio"} > ... > I do have a custom route for this /portfolio/index page: > > map.portfolio ''portfolio/:id'', :controller => ''portfolio'', :action => > ''index'' > > I don''t know if that is involved in this.Yes, the custom route is the problem. It''s taking the "live_search" action as an id. Add an ":id => /[0-9]+/" option to the route so that only numeric ids are re-routed. -- We develop, watch us RoR, in numbers too big to ignore.
Thanks very much, Mark - it was a big help. Steve On 2/11/06, Mark Reginald James <mrj@bigpond.net.au> wrote:> > Steve Odom wrote: > > > Parameters: {"action"=>"index", "id"=>"live_search", "q"=>"pau", > > "controller"=>"portfolio"} > > ... > > I do have a custom route for this /portfolio/index page: > > > > map.portfolio ''portfolio/:id'', :controller => ''portfolio'', :action => > > ''index'' > > > > I don''t know if that is involved in this. > > Yes, the custom route is the problem. It''s taking the "live_search" > action as an id. Add an ":id => /[0-9]+/" option to the route > so that only numeric ids are re-routed. > > -- > We develop, watch us RoR, in numbers too big to ignore. > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060212/7cb7e1f0/attachment.html