Rails 3 remote link click triggers different request on second click

By : David R
Source: Stackoverflow.com
Question!

I have a Rails app that was working well until I upgraded ruby, rubygems, and my gems.

Almost all of my links are remote links. When I make the first request by clicking on one of these links, Fancybox is triggered and opens the new content correctly. When I close the box and click the same link again the request that is generated is completely different. It requests the index and consequently Fancybox is populated with the index response.

Sample link:

<a href="/companies/87/edit" data-remote="true">Handmade Design</a>

First request:

Started GET "/companies/89/edit" for 127.0.0.1 at 2013-03-18 15:34:26 -0700
Processing by CompaniesController#edit as JS

Second request:

Started GET "/companies" for 127.0.0.1 at 2013-03-18 15:34:26 -0700
Processing by CompaniesController#index as */*

I'm relying on the jquery-rails gem, fancybox, and the remotipart gem if that helps. Since these were all updated it seems like the error could be in one of these areas, but that fact that the requests are totally different makes me think it's something with Rails formats. Here is what the edit action looks like in the Companies controller:

#/controllers/companies_controller.rb
respond_to :html, :json
respond_to :js,   :only => [:new, :create, :edit, :update, :destroy]

# ...

# GET /companies/1/edit
def edit
  respond_with @company
end

I use a before filter to grab the company.

Any help or clues would be much appreciated.

UPDATE

The second request appears to always be a request for the current page.

UPDATE

I've isolated this to a JS issue. It appears to not be an issue with Rails or remote links.

By : David R


Answers

I found the source of the issue. When Fancybox closes it doesn't correctly replace the HTML it is takes when it opens. The issue and some solutions are documented here:

Fancy box not opening iFrame second time

By : David R


This video can help you solving your question :)
By: admin