Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

@koshi_an

ページ単位のjavascript読み込み

app/assets/javscripts/application.jsの修正

以下のコードの削除

application.js
//= require_tree .

共通のjavascript配置
common.jsの呼び出し

application.js
//= require common

コントローラ/アクション.js 形式でjavascriptの配置

app/assets/javascripts/top/index.js とか
app/assets/javascripts/top/create.js とか

views/layouts/application.html.erb の修正

<!DOCTYPE html>
<html>
<head>
  <title>TestJs</title>
  <%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track' => true %>
  <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
  <%= csrf_meta_tags %>

<%= javascript_include_tag "#{params[:controller]}/#{params[:action]}" if Rails.application.assets.find_asset("#{params[:controller]}/#{params[:action]}.js") %>

</head>
<body>

<%= yield %>

</body>
</html>

config/initializers/assets.rb の追加

Rails.application.config.assets.precompile += %w( top/index2.js )
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?