简体   繁体   中英

JQuery not being loaded in rails 3.1

Currently, it seems as though my jquery and other js files aren't being included in my views..

I have this gem in my gem file:

gem 'jquery-rails', '>= 1.0.12'

I'm using rails 3.1.0

in my header is:

<head>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>

The html coming through the view is this:

<head>
  <link href="/assets/all.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="/assets/defaults.js" type="text/javascript"></script>
  <meta content="authenticity_token" name="csrf-param" />
<meta content="scIP+mIH7ON1DYP9XWeSidk/5i4DizpuwQOP8mcxA9M=" name="csrf-token" />
</head>

in my config/application.rb file I also have:

config.action_view.javascript_expansions[:defaults] = %w(jquery rails)

Any help would be greatly appreciated

In rails 3.1, you want this instead:

<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>

That way it'll use the asset pipeline. Without it, it's looking for all.css and defaults.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM