How to render a partial and and a javascript file in the same time in Rails ?

Posted by master2004 on Stack Overflow See other posts from Stack Overflow or by master2004
Published on 2010-04-11T00:26:51Z Indexed on 2010/04/11 0:33 UTC
Read the original article Hit count: 698

Hi.

My main intention is to keep the functionality independent form the Javascript, to have it gracefully degradable. Maybe I am trying to go where I want the wrong way but the main idea is:

  • there are some jQuery UI tabs and when the user presses a link, a new tab is added corresponding to that action
$("#tabs").tabs('add', "/groups", "My Groups");
  • the controller identifies the AJAX request and renders only the partial for that tab
if request.xhr?
  render  :partial => "index_tab"
end
  • at this point I would like the Javascript file associated with the /groups/index action to be executed as well, meaning the index.js.erb file in the groups folder.
  • because of the "only one render" rule I couldn't think of a nice way to do it and I am in need of a fast solution.

Thank you for any suggestions you might have.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about JavaScript