1] Write the code in the view, i.e., in the html.erb itself.
3] In case you want to make the request as Ajax:
:remote => true.
In the called action, use code as follows:
def action respond_to do |format| format.js end end