Question regarding proper use of render :js for handling AJAX requests

Dear rails gurus,

Is this a proper way to write the following render :js argument inside a
controller for handling a simple AJAX response (div update) to a JS
using rails 3.2.1?

render :js => ‘$(“span#main”).html("’ +
escape_javascript(‘app/views/main/my_file.html.erb’)) + ‘");’

While this code is working, it seems a little clunky e.g. the
call feels out-of-place somehow… but then again, what do I know? :stuck_out_tongue:

Thanks for your comments/advice! The main reason why I am doing this is
a shortcut to avoid creating a .js.erb file, where I would have

escape_javascript(render template:‘main/my_file.html.erb’)

instead; trying to run this inside of the controller gave me a couple

  1. the “render template” returned a length-1 array instead of a string,
    which I had to reference the 0th-element of in order to get
    escape_javascript not to throw a “gsub on Array” error
  2. can’t use render twice in the same line (double redirect error) led
    to the alternative “…” idea

Forgive me if this question has been posted before, and thank you all in
advance for your kind assistance.