Rails, def destroy, is not responding with the destroy.js.erb
Here is my method:
# DELETE /Groups/1
# DELETE /Groups/1.xml
def destroy
@group = Group.find(params[:id])
@group.destroy
respond_to do |format|
format.js
end
end
In the view I have:
<a href="/groups/122" data-confirm="Are you sure?" data-method="delete" rel="nofollow" >Delete</a>
However on delete the log shows:
S
tarted POST "/groups/128" for 127.0.0.1 at Fri Apr 22 22:21:31 -0700 2011
Processing by GroupsController#destroy as HTML
Parameters: {"authenticity_token"=>"J+A2DN87qoigNxw97oK6NWqPQvXt7KAwLMAM7Er/eWM=", "id"=>"128"}
.....
Completed 406 Not Acceptable in 372ms
The destory.js.erb is never being called. Any ideas why? Thanks
ok, well, a couple of issues here:
first,
this link is not remote, you can see it in the log you provided:
to make your link submit an ajax request add :remote => true ( the same way you already have :confirm => ‘Are you sure?’ and :method => :destroy )
second, you should disable layout rendering when responding with javascript.
So, your action might look like:
To make it easier, I have added this to my contoller:
so that layout won’t be rendered if request is of xhr type. Then you could leave you action as it is now and it should work