0

I am using Rails 3.2.12 and the latest jquery-mobile gem.

In the layout:

<%= javascript_include_tag "mobile" %>

In mobile.js:

//= require jquery
//= require jquery_ujs
//= require jquery.mobile

Now whenever I manually load a page by typing the full URL, everything seems to work as it should. However, when I click on a link or submit a form, there is a strange "double submission" happening.

Here's an example of the server console when logging in:

  1. Submit the login form

    Started POST "/login/signin?class=form" for 127.0.0.1 at 2014-02-10 11:21:58 +0100
    Processing by LoginController#signin as HTML
    Parameters: {"utf8"=>"✓", "authenticity_token"=>"0LlkpMMR8/4HMgzlWob15TSxvNvCIPUaW0Zuutygos8=", "email"=>"director@demo.foot", "password"=>"[FILTERED]", "connect"=>"Sign in", "class"=>"form"}
    
  2. After processing the signin, the request gets redirected to home/myome as it should

    Started GET "/home/myhome" for 127.0.0.1 at 2014-02-10 11:21:58 +0100
    Processing by HomeController#myhome as HTML
    
  3. Now this is when the weird stuff happens, as a GET method is fired out of nowhere

    Started GET "/login/signin?class=form" for 127.0.0.1 at 2014-02-10 11:22:00 +0100
    Processing by LoginController#signin as */*
    
  4. Followed by:

    Started GET "/home" for 127.0.0.1 at 2014-02-10 11:22:00 +0100
    Processing by HomeController#index as */*
    

Similarily, clicking on simple links fires two identical GET requests.

When I disable ajax with ajaxEnabled = false, the links are working.

One explanation could be including jquery twice somehow but I cannot figure out when and how. I have seen a couple of similar threads such as this one and have made sure not to precompile assets in development mode, but to no avail.

edit: I gave up on this a while ago when I realised that all the ids, throughout the site's pages needed to be unique in order to use jquery mobile's Ajax loading abilities. This was where my issues were coming from.

Since I am applying jquery mobile to an existing large website, with lots of forms and manually set ids, I have chosen to keep it simple for now and disable Ajax.

Building from scratch, one would have to come up with a good system to ensure unique ids throughout the site.

Here's a link with some advice on this subject: http://metaskills.net/2011/08/24/jquery-mobile-and-rails/

Community
  • 1
  • 1
NicoFerna
  • 603
  • 3
  • 11
  • What does your controller action look like? Maybe you're using a `redirect` action, which re-renders the page? – Richard Peck Feb 10 '14 at 13:57
  • The links fail the same way whichever the action is, whether there is a direct render or a redirect action in between. I do not think this is the issue here, I have tried with the most simple link_to actions and I always end up with the same problem. I have disabled ajax for now, but it's a shame, hope I can find a solution at some point! – NicoFerna Feb 13 '14 at 14:10

0 Answers0