Topic: link_to remote call / error when opening in new tab

Hi all,

in my view i want to load a specific partial when i click on a certain link. Everythings works so far:

View:

<%= link_to image_tag('social/24x24/facebook.png'), event_social_content_url( :id => event.id, :network => 'facebook'),   :remote => true %>
<%= link_to image_tag('social/24x24/google.png'), event_social_content_url( :id => event.id, :network => 'google'),   :remote => true %>
<div id="socialbookmarks_<%= event.id %>"></div>

Controller:

class AjaxController < ApplicationController
  def social
    @event = Event.find(params[:id])
    @network = params[:network]
    render :layout => false
  end
end  

JS:

$("#socialbookmarks_<%= @event.id %>").html("<%= escape_javascript(render @network) %>");

If i click on on of the links the facebook or google partial will render inside the div as expected. But if i open the link inside a new window/tab i get an error message that the template social is not found.

How can i prevent that the link will be opened inside a new window and showing a error message to the user ? I would expect on somehow that nothing will happen if the user opens the link inside a new window ( like linking to # ) and the current page will be shown.

Re: link_to remote call / error when opening in new tab

Not sure if this is the problem, but make sure your paths are not relative. Use exact paths, this might alleviate the "missing" problem.

Remember to edit your topic title and add "[SOLVED]" if your question has been answered!

Follow me!

Re: link_to remote call / error when opening in new tab

When you open the link in new tab, the params passed to link_to, i.e., 'remote' or 'method' won't be taken into consideration and browser will try to open the href being passed to the link. Thats why you are getting that error.