views:

62

answers:

1

I want a table to do CRUD, but I want it in an Ajax way, how can I modify the default RoR behavior, any suggestions on that?

I tried comment these code in destroy method, but it don't work, it saw missing the destroy.erb:

respond_to do |format|
  format.html { redirect_to(categories_url) }

  format.xml  { head :ok }
end
+1  A: 

It will default to HTML if you don't give (and accept) a different response. Check out this railscast to see how to set up an AJAX request and response with RJS (there's another on how to do it with jQuery).

Basically you'll need a format.js line. You can also make a view of the form .js.erb where you write JavaScript to run on the server response.

As a side note though, unless you have a very specific website, I'd suggest not doing only AJAX. It's not very accessible for users without JavaScript, like blind users with a screenreader.

Adam Stegman
It also annoys us lazy bastards, er... power users who navigate via keyboard because we can't be bothered to reach for the mouse.
EmFi