I'm curious what is the best way to respond to an ajax request, is it sending json, and then parse it at the client side (for example with pure) or should I render javascript at the server side and return the result(with a js.erb template)?
Using js.erb
templates tends to be simpler and encourages you to keep your application logic in your Rails controllers. For traditional applications, where little to no application logic is handled in javascript, this can be a good thing.
On the other hand, using JSON encourages you to develop your Rails app more as an API server for a javascript-heavy client application. If you're looking to do your core CRUD actions over ajax and rarely reload the page, this is probably fits better with your application's style.
Which is best in a particular situation depends on both the type of application you're looking to build and the attributes of the particular request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With