Q:

how can i render a template as well as a JS file BOTH in a controller action

i have a scenario where in edit action ,i need to render the edit.html.erb as well as trigger the edit.js.erb file as well.right now i have
      def edit
    @page_id = params[:id]
    respond_to do |format|
    format.html
    format.js
    end
  end

but only the view is renderring ,but my edit.js.erb is still not triggered. 

A:

With both ansers you can get it working, but you do not follow conventions.  The edit.js is meant for Ajax-calls. 
What you seem to be doing, is using partials to build up your page.  Then you really should follow naming conventions (starting the filename with _) to be clear for other programmers. 
Second, you always need to make sure your site can work without javascript, so your Edit page never should require any Javascript to work.  The javascript is complementary to improve user experience (like using ajax to make edits without a page-refresh). 
Summing up:
- move the 'required' javascript code to your edit.html.erb. 
- only use the edit.js.coffee to handle the updates to the existing webpage if Ajax is activated, use as much of the js from the edit.html.erb. 
- Put the rest of the shared code into partials, like _niceedit.js.coffee and render it using 'render :partial=>'...
Follow conventions, it will help you later on and when using test services etc.