我想做的是将每个视图的Javascript包含在一个
content_for :head块中,然后
yield在应用程序布局中添加到该块。例如
如果很短,则:
<% content_for :head do %> <script type="text/javascript"> $(function() { $('user_rating_positve').click(function() { $('some_div').show(); } }); </script><% end %>或者,如果更长,则:
<% content_for :head do %> <script type="text/javascript"> <%= render :partial => "my_view_javascript" </script><% end %>
然后,在您的布局文件中
<head> ... <%= yield :head %></head>



