Forum: Ruby on Rails problem with AJAX when using passenger

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Tam K. (Guest)
on 2009-03-15 00:12
Hello,

I just switched to using Passenger from using Apache/Mongrel cluster.

I have an AJAX form:
--------------------------------
<% form_remote_tag  :url => {:controller => "networks", :action =>
'search'},
          :update => 'searchResults',
          :loading => "Element.hide('goBtn');
Element.show('fts-loader')",
          :complete =>
"Element.show('goBtn');Element.hide('fts-loader'); " do %>

            <table border="0" bgcolor="#E5E5E5" cellpadding="0">
              <tr>
                <td><span
class="headerTextGreen">Search&nbsp;</span></td>
                <td><%= text_field_tag 'search_phrase', '', :size =>
'20', :class=>'search-box' %></td>
                <td width="20">
                   <%= image_submit_tag 'btnGo.gif', :id => 'goBtn',
:class => 'btnSearch' %>
                    <%= image_tag 'searchWait.gif', :id =>
'fts-loader1', :style => 'display:none', :size => "15x14" %>
                </td>
              </tr>
            </table>
          <% end %>
-------------------------------
This form takes search string and then displays search results in div
inside the page ,searchResults, and this was working fine with
Apache/Mongrel.

After using Passenger it still works but instead of displaying search
results in the "searchResults" div, it refreshes the whole page with the
search results as the div is the only page that the page has.

Any ideas?

Thanks,

Tam
Tom Z Meinlschmidt (Guest)
on 2009-03-15 02:48
(Received via mailing list)
what's in the source of generated page? c&p form code

Tam K. wrote:
> Element.show('fts-loader')",
>                    <%= image_submit_tag 'btnGo.gif', :id => 'goBtn',
> Apache/Mongrel.
>
> After using Passenger it still works but instead of displaying search
> results in the "searchResults" div, it refreshes the whole page with the
> search results as the div is the only page that the page has.
>
> Any ideas?
>
> Thanks,
>
> Tam


--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===============================================================================
Tam K. (Guest)
on 2009-03-15 03:34
Thanks Tom: Here is the Ruby code

---------------------
  def search
    @page = params[:page]
    @page ||= 1;
    @search_phrase = params[:search_phrase]
    @search_phrase ||= ''

    @users = User.search(@search_phrase,
              :sphinx => {:limit => $NUM_USER_SEARCH_RSLTS, :page =>
@page,:weights => [100,60,20,20]},
              :per_page => $NUM_USER_SEARCH_RSLTS, :page => @page)
    @userColleagues =
User.find_by_id(session[:user_id]).colleagues(:all, :conditions =>
["networks.mutual = ?" , true])
    @is_network_owner = false
    @is_network_owner = true if params[:id].to_i==session[:user_id]

    render :partial => 'user_search_results', :locals => {:users =>
@users, :@userColleagues => @userColleagues, :@is_network_owner =>
@is_network_owner}

  end
----------------
Thanks,
Tam
Tom Z Meinlschmidt (Guest)
on 2009-03-15 10:36
(Received via mailing list)
Tam.. I meant html source of generated page with the form...

tom

Tam K. wrote:
>               :sphinx => {:limit => $NUM_USER_SEARCH_RSLTS, :page =>
> @is_network_owner}
>
>   end
> ----------------
> Thanks,
> Tam


--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===============================================================================
Tam K. (Guest)
on 2009-03-15 17:22
<form onsubmit="new Ajax.Updater('searchResults', '/network/search',
{asynchronous:true, evalScripts:true,
onComplete:function(request){Element.show('goBtn');Element.hide('fts-loader');
}, onLoading:function(request){Element.hide('goBtn');
Element.show('fts-loader')}, parameters:Form.serialize(this)}); return
false;" method="post" action="/network/search">
<table cellpadding="0" border="0" bgcolor="#e5e5e5">
<tbody>
<tr>
<td>
<span class="headerTextGreen">Search </span>
</td>
<td>
<input id="search_phrase" class="search-box" type="text" value=""
size="20" name="search_phrase"/>
</td>
<td width="20">
<input id="goBtn" class="btnSearch" type="image"
src="/images/btnGo.gif?1237061985"/>
<img id="fts-loader1" width="15" height="14" style="display: none;"
src="/images/searchWait.gif?1237061985" alt="Searchwait"/>
</td>
</tr>
</tbody>
</table>
</form>

Thanks Tom...

Cheers,
Tam
Tom Z Meinlschmidt (Guest)
on 2009-03-15 20:01
(Received via mailing list)
try to add :method=>:get into your form_remote_tag ...

<% form_remote_tag (
   :url => {:controller => "networks", :action => 'search'},
   :method => :get,
   :update => 'searchResults',
   :loading => "Element.hide('goBtn'); Element.show('fts-loader')",
   :complete => "Element.show('goBtn');Element.hide('fts-loader');") do
%>

tom

Tam K. wrote:
> <span class="headerTextGreen">Search </span>
> </td>
> </tr>
> </tbody>
> </table>
> </form>
>
> Thanks Tom...
>
> Cheers,
> Tam


--
===============================================================================
Tomas Meinlschmidt, MS {MCT, MCP+I, MCSE, AER}, NetApp Filer/NetCache

www.meinlschmidt.com  www.maxwellrender.cz  www.lightgems.cz
===============================================================================
Jeremy Olliver (Guest)
on 2009-03-16 11:14
(Received via mailing list)
Other than ensuring the routing (which seems to be connecting to some
action or other), I recommend you also check the submit button you are
using.

The form remote tag builds a form which has a javascript method called
onsubmit() which is what submits the ajax form. If you use some type
of custom submit button that one way or another calls form.submit (how
non ajax forms are submitted) rather than onsubmit, then you will get
what you are seeing now, with the javascript response shown as a page.
Tam K. (Guest)
on 2009-03-17 06:18
Thanks Tom and Jermy. The problem was resolved by using the right
version of Rails. The server version was 2.2.2 and my local computer
version is 2.1.0. The code I posted worked fine after installing Rails
2.1.0 gem on my server!
I might try the solutions you provided if I use later verion of Rails,
the code I write might be getting interpreted differently with Rails
2.2.2.
Cheers,
Tam
This topic is locked and can not be replied to.