Disable application layout for custom Facebook share button in Rails

I've implemented custom buttons for Twitter and Facebook sharing in my Rails app, and thus have had to use Javascript below to open popups when they are clicked:

$('.popup, #fbShare').click(function (event) {
event.preventDefault();
window.open($(this).attr("href"), "popupWindow", "width=600,height=400,scrollbars=yes");
return false;
});

The Twitter button works fine but the Facebook share button keeps attempting to yield the default application layout and giving an error message of:

ActiveRecord::RecordNotFound in UsersController#show

Couldn't find User with id=undefined"

The javascript file is named search.js.erb, and I'm trying to share a link from the home page, so I would assume I need to add something to the ApplicationController, but this error message makes it seem like the error is with UsersController (which does route to root, but I'm not on that user page when attempting to share).

I've had a look around and found two solutions proffered: 1 is to add

 layout proc{|c| c.request.xhr? ? false : "application" }

to the ApplicationController: that doesn't seem to work. Another is to add

 def respond
respond_to do |format|
  format.html
  format.js { render :layout => false }
end
end

to the controller; I've tried adding this to both Application and UsersController, with no luck. I've managed to use "render :layout => false" before with success but am unsure how to implement it in this case.

Answers


Added the "popup" class to the Facebook link as well and removed the #fbShare from the jQuery, now it works, I think the id was confusing the Rails app into thinking it was a user id?


Need Your Help

Why the sticky footer is not working on Samsung smartphone Note 2, built in browser?

android html css html5 css3

I am using sticky footer design for my website that I have adopted from Responsive Web Design with HTML5 and CSS3 (second edition) from Ben Frain. It is working perfectly on major modern browsers b...

YUV Overlay in SlimDX / DirectX?

video ffmpeg directx yuv slimdx

I decode a video file using ffmpeg and once decoded I get a YUV image.