为什么我的javascript加载所有我的控制器

时间:2016-09-19 20:44:59

标签: javascript jquery ruby-on-rails api turbolinks

我有一个user.js文件,我想专门为我的用户控制器加载,但它也在我的主页控制器上运行。

的application.js

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= require RGraph.common.core
//= require RGraph.common.dynamic
//= require RGraph.common.tooltips
//= require RGraph.line
//= require RGraph.bar
//= require RGraph.hprogress
//= require_tree 

application.html.erb

<!DOCTYPE html>
<html lang="en">
    <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Testing</title>
    <meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Testing" %>">
    <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
    <%= Gon::Base.render_data %> 
    <%= csrf_meta_tags %>
    <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  </head> 

  <body>
    <%= yield %>
  </body>  
</html>

主页/ index.html.erb

<div class="jumbotron">
    <div class="container">
      <h1>Welcome!</h1>
      <p>Register to get started.</p>
      <p>
        <%= link_to 'Register', new_user_registration_path, class: 'btn btn-primary btn-lg' %>
      </p>
    </div>

</div>

0 个答案:

没有答案