javascript_include_tag generates a <script> tag in the output. When
the browser renders your page, it looks at that script tag and
requests myscript.js from your server. By now, the original controller
and its @user variable are long gone, you're instead looking at the
@user from a new controller, which is apparently null. one way of
dealing this might be
<% content_for :head do %>
<%= javascript_tag "var js_user_name = #{@user.name.to_json};"
<%= javascript_include_tag 'my script' %>
<% end %>
which creates a (javascript) variable called js_user_name that your
javascript would be able to use. Another option would be to pass
information about which user to pick via a query parameter (i.e.
instead of the url requested being /javascripts/myscript.js it would
be /javascripts/myscript.js?user_id=123), and have the controller that
renders the javascript set up @user accordingly.
Fred