I have an otherwise functioning rails project where I’m trying to update some form controls to work over AJAX instead of HTML. But my controller continues to handle it as HTML instead of JS and I’m not sure why.
The link I’m trying to make remote in my users/index.html.erb:
<%= link_to 'Disable', disable_user_path(user), :confirm => 'Are you sure?',
:method => :put, :remote => true %>
Rendered as:
<a href="/users/1/disable" data-confirm="Are you sure?" data-method="put"
data-remote="true" rel="nofollow">Disable</a>
My Users Controller:
def disable
@user = User.find(params[:id])
if @user.update_attribute(:enabled, false)
respond_to do |format|
format.html { redirect_to root_path, :flash => { :success => "Disabled." }}
format.js {}
end
else
redirect_to root_path, :flash => { :error => @user.errors.full_messages }
end
end
My includes in application.html.erb:
<%= javascript_include_tag "//ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "//ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js", "jquery.rails.js", "application" %>
I think I pulled down the third and fourth files from a standard place, but if those are possibly the culprit I can look inside them or track down more information about them.
When I test it, it doesn’t prompt me with “Are you sure?” and it responds with the redirection and “Disabled” flash message, and the server logs confirm it’s being handled as html.
Started GET “/users/1/disable” for 127.0.0.1 at 2012-02-11 17:17:31
-0200 Processing by UsersController#disable as HTML
You may still need to include the unobtrusive javascript adapter if you have not done so already.