My rails app has lots of client-side javascript callbacks following ajax requests, but I have been unable to get the proper flow through route > controller > erb files to work.
Here is one example, starting with the ajax request:
$(initElement).on("click", function(){
event.preventDefault();
var url = "http://localhost:3000/login";
$.ajax({
url: url,
method: "GET",
dataType: "html"
}).done(function(){
console.log("*** ajax success T ***");
displayObject.toggleSelectionLabels("show");
}).fail(function(){
console.log("*** ajax fail T ***");
});
});
The route in routes.rb
get "/login" => "sessions#login"
The sessions controller login action:
def login
puts "******* login " + "*" * 21
end
The login.html.erb file I am expecting from the server:
<% @page_title = "UserAuth | Login" %>
<div class="form-column login">
<h1>Log in</h1>
<div class="tag-edits photo-form">
<%= form_tag(:action => 'login_attempt') do %>
... edited out...
<% end %>
</div>
</div>
The ajax request fuinds the route, returns as a "success" and the toggleSelectionLabels callback runs, but no erb content appears. Does ajax prevent the normal processing within rails?