By using the remote:true
attribute on a form and responding from the controller with :js
, Rails is instructed to run a specific javascript file.
For instance, when deleting a user, you would have the User controller with the Destroy action. Then, you would create a file called views/users/destroy.js.erb
containing something like this:
$("ul#users").html("<%= j render partial: 'user_list' %>");
My question is... Is there a way to streamline this process and avoid having multiple small files scattered throughout the application? If all I need is to render a partial with some variables, is there a quicker method such as:
respond_with render :js, with: 'partial_foo', on: '#selector .bar'
Is there a shortcut available for this?