I’m running a simple AJAX post to my server and the respond_to .js block is returned as a 200 success but is not executed. Am I missing something in my configuration or in my code for the execution the return js code? I’m using Ruby on Rails 3.2.9.
javascript:
$("#test-submit").on("click",function(event){
$.ajax({
type: "POST",
url: '/users',
dataType: 'json',
data: {
"test" : "test-data"
}
});
event.preventDefault();
});
controller action:
def create
user = User.find(current_user)
respond_to do |format|
format.js { }
end
end
user create.js.erb:
alert('hai');
You expect JSON data, not executable script. Try to change this line to