R – How to modify the default RoR behavior to AJAX CRUD

ajaxrubyruby-on-rails

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

Best Answer

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.