When a controller responds to a link_to_remote with a redirect_to, the
link_to_remote gets a success callback, this would seem like a bug to
me, at a minimum it should return a failure?
This is driving me crazy because all the login engines/generators
respond to an authentication error with a redirect_to. The work around
is to change them to all do a
render :layout => false, :status => 500 if request.xhr?
But that seems a little overkill.
here is my simple test… clicking the first link returns a failure as
expected, clicking the second link returns success… If this isn’t a
bug can someone explain to me why – thanks
in my app/controllers/test_controller.rb…
def test
unless request.get?
id= params[:id]
if id == “1”
render :text => “login”, :layout => false, :status => 500
else
redirect_to :action => ‘index’
end
end
end
in my app/views/test/test.rhtml…
<%= link_to_remote “test_good”,
:update => “test_div”,
:url => { :controller => ‘test’ :action => ‘test’, :id => 1},
:loading => “alert(‘loading’)”,
:success => “alert(‘success’)”,
:failure => “alert(‘failed’)”,
:position => “after”
%>
<%= link_to_remote "test_bad", :update => "test_div", :url => { :controller => 'test', :action => 'test', :id => 2 }, :loading => "alert('loading')", :success => "alert('success')", :failure => "alert('failed')", :position => "after" %>