現在簡単なアプリケーションを作成して練習しています。
scaffoldで作成したものに、bootstrapを適用させるという流れの中で、質問のエラーが起きました。
自分で行ったことは、まずsprocketsやHelper、アセットについて初めて見かけたので、これについてググってみました。
そして当てずっぽうかもしれませんが、仮説を立ててみましたが、未だ解決に至らないので一緒にみてもらえないでしょうか。
###1、まずアセットについて調べてみました
"Assetとは、Webアプリケーションの直接のレスポンス以外の構成要素のことを指します。Javascript、CSS、画像などがこれにあたります。Asset Pipelineを使うことでこのAssetを簡単に利用出来るようになります。"
Javascript、CSS、画像。これらをAssetという。(railsとは別の言語や外部リンクのこと?)というところまで把握しました。
###2、アセットパイプライン
"JavaScriptやcss、画像ファイルといったHTMLに付随する細々としたファイルたち(アセットファイル)を連結したり圧縮したりすることで効率的にアクセスすることができるrailsの機能のこと。"
アセットパイプラインでjavascriptとcssがまとめられるということ、
ERB、CoffeeScript、SCSS などが使えるようになるということまでわかった。
###3、Sprocketsの役割
"アセットパイプラインの基盤になるgem。
アセットファイルへのパスの管理。圧縮。結合。アセットファイル間の依存性の解決。アセットファイルのコンパイル。翻訳。"
###4、Helperについて
"viewをよりシンプルにDRYに書くためのモジュール。view以外もhelpできるけど、基本的にはviewをhelpしてくれるもの"
これらを踏まえての推測
Sprockets::Rails::Helper::AssetNotFound in Books#index
Indexの14行目のアセットがない。
アセットとはJSとCSSのことで、railsではアセットパイプラインという機能がある。
Sprocketsとはアセットパイプラインの基盤になるgemのことのようだが、自分のファイルにはsprockets〜というgemが編集されていない。
Helperとはビューを助ける、シンプルに書くためにコードを補助するものと解釈した。
Q⓵>Sprocketsとはアセットパイプラインの基盤になるgemのことのようだが、自分のファイルにはsprockets〜というgemが編集されていない。
A⓵>gem fileに sprocketsを追加する。⇨gem 'sprockets’を記載する
Q⓶Helperとはビューを助ける、シンプルに書くためにコードを補助するものと解釈した。
A⓶>index画面の14行目を補助するコードをヘルパーに書かなくてはいけない。
application_heiperかbooks_helperか不明。
〜推測に対して〜
qiitaで見つけた方法でgem 'sprockets' というのがあり、現時点で自分でできそうなのはこれを試すことですが、ググっていてもなかなか見当たらないので、試すのに躊躇しています。
長くなってしまいましたが、お願いいたします。
:追記
Gemfile
rb
1 2source 'https://rubygems.org' 3git_source(:github) { |repo| "https://github.com/#{repo}.git" } 4 5ruby '2.5.1' 6 7# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 8gem 'rails', '~> 5.2.2' 9# Use sqlite3 as the database for Active Record 10gem 'sqlite3' 11# Use Puma as the app server 12gem 'puma', '~> 3.11' 13# Use SCSS for stylesheets 14gem 'sass-rails', '~> 5.0' 15# Use Uglifier as compressor for JavaScript assets 16gem 'uglifier', '>= 1.3.0' 17# See https://github.com/rails/execjs#readme for more supported runtimes 18# gem 'mini_racer', platforms: :ruby 19 20# Use CoffeeScript for .coffee assets and views 21gem 'coffee-rails', '~> 4.2' 22# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks 23gem 'turbolinks', '~> 5' 24# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 25gem 'jbuilder', '~> 2.5' 26# Use Redis adapter to run Action Cable in production 27# gem 'redis', '~> 4.0' 28# Use ActiveModel has_secure_password 29# gem 'bcrypt', '~> 3.1.7' 30 31# Use ActiveStorage variant 32# gem 'mini_magick', '~> 4.8' 33 34# Use Capistrano for deployment 35# gem 'capistrano-rails', group: :development 36 37# Reduces boot times through caching; required in config/boot.rb 38gem 'bootsnap', '>= 1.1.0', require: false 39 40group :development, :test do 41 # Call 'byebug' anywhere in the code to stop execution and get a debugger console 42 gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] 43end 44 45group :development do 46 # Access an interactive console on exception pages or by calling 'console' anywhere in the code. 47 gem 'web-console', '>= 3.3.0' 48 gem 'listen', '>= 3.0.5', '< 3.2' 49 # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 50 gem 'spring' 51 gem 'spring-watcher-listen', '~> 2.0.0' 52end 53 54group :test do 55 # Adds support for Capybara system testing and selenium driver 56 gem 'capybara', '>= 2.15' 57 gem 'selenium-webdriver' 58 # Easy installation and use of chromedriver to run system tests with Chrome 59 gem 'chromedriver-helper' 60end 61 62# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 63gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] 64 65 66 67#あえて開けて記入 68gem 'less-rails' 69 70gem 'therubyracer' 71 72gem 'execjs' 73 74gem 'twitter-bootstrap-rails'
index.html.erb
rb
1<%- model_class = Book -%> 2<div class="page-header"> 3 <h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1> 4</div> 5<table class="table table-striped"> 6 <thead> 7 <tr> 8 <th><%= model_class.human_attribute_name(:id) %></th> 9 <th><%= model_class.human_attribute_name(:title) %></th> 10 <th><%= model_class.human_attribute_name(:author) %></th> 11 <th><%= model_class.human_attribute_name(:publisher) %></th> 12 <th><%= model_class.human_attribute_name(:regist_date) %></th> 13 <th><%= model_class.human_attribute_name(:created_at) %></th> 14 <th><%=t '.actions', :default => t("helpers.actions") %></th> 15 </tr> 16 </thead> 17 <tbody> 18 <% @books.each do |book| %> 19 <tr> 20 <td><%= link_to book.id, book_path(book) %></td> 21 <td><%= book.title %></td> 22 <td><%= book.author %></td> 23 <td><%= book.publisher %></td> 24 <td><%= book.regist_date %></td> 25 <td><%=l book.created_at %></td> 26 <td> 27 <%= link_to t('.show', :default => t("helpers.links.show")), 28 book_path(book), :class => 'btn btn-default btn-xs' %> 29 <%= link_to t('.edit', :default => t("helpers.links.edit")), 30 edit_book_path(book), :class => 'btn btn-default btn-xs' %> 31 <%= link_to t('.destroy', :default => t("helpers.links.destroy")), 32 book_path(book), 33 :method => :delete, 34 :data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) }, 35 :class => 'btn btn-xs btn-danger' %> 36 </td> 37 </tr> 38 <% end %> 39 </tbody> 40</table> 41 42<%= link_to t('.new', :default => t("helpers.links.new")), 43 new_book_path, 44 :class => 'btn btn-primary' %>
application.html.erb
rb
1<!DOCTYPE html> 2<html lang="en"> 3 <head> 4 <meta charset="utf-8"> 5 <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> 6 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 7 <title><%= content_for?(:title) ? yield(:title) : "Dokusho" %></title> 8 <%= csrf_meta_tags %> 9 10 <%= stylesheet_link_tag "application", :media => "all" %> 11 12 <!-- For third-generation iPad with high-resolution Retina display: --> 13 <!-- Size should be 144 x 144 pixels --> 14 <%= favicon_link_tag 'apple-touch-icon-144x144-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '144x144' %> 15 16 <!-- For iPhone with high-resolution Retina display: --> 17 <!-- Size should be 114 x 114 pixels --> 18 <%= favicon_link_tag 'apple-touch-icon-114x114-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '114x114' %> 19 20 <!-- For first- and second-generation iPad: --> 21 <!-- Size should be 72 x 72 pixels --> 22 <%= favicon_link_tag 'apple-touch-icon-72x72-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png', :sizes => '72x72' %> 23 24 <!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: --> 25 <!-- Size should be 57 x 57 pixels --> 26 <%= favicon_link_tag 'apple-touch-icon-precomposed.png', :rel => 'apple-touch-icon-precomposed', :type => 'image/png' %> 27 28 <!-- For all other devices --> 29 <!-- Size should be 32 x 32 pixels --> 30 <%= favicon_link_tag 'favicon.ico', :rel => 'shortcut icon' %> 31 32 <%= javascript_include_tag "application" %> 33 34 <!-- Le HTML5 shim, for IE6-8 support of HTML elements --> 35 <!--[if lt IE 9]> 36 <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.2/html5shiv.min.js" type="text/javascript"></script> 37 <![endif]--> 38 </head> 39 <body> 40 41 <div class="navbar navbar-default navbar-static-top"> 42 <div class="container"> 43 <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse"> 44 <span class="icon-bar"></span> 45 <span class="icon-bar"></span> 46 <span class="icon-bar"></span> 47 </button> 48 <a class="navbar-brand" href="#">Dokusho</a> 49 <div class="navbar-collapse collapse navbar-responsive-collapse"> 50 <ul class="nav navbar-nav"> 51 <li><%= link_to "Link1", "/path1" %></li> 52 <li><%= link_to "Link2", "/path2" %></li> 53 <li><%= link_to "Link3", "/path3" %></li> 54 </ul> 55 </div> 56 </div> 57 </div> 58 59 <div class="container"> 60 <div class="row"> 61 <div class="col-lg-9"> 62 <%= bootstrap_flash %> 63 <%= yield %> 64 </div> 65 <div class="col-lg-3"> 66 <div class="well sidebar-nav"> 67 <h3>Sidebar</h3> 68 <ul class="nav nav-list"> 69 <li class="nav-header">Sidebar</li> 70 <li><%= link_to "Link1", "/path1" %></li> 71 <li><%= link_to "Link2", "/path2" %></li> 72 <li><%= link_to "Link3", "/path3" %></li> 73 </ul> 74 </div><!--/.well --> 75 </div><!--/span--> 76 </div><!--/row--> 77 78 <footer> 79 <p>© Company 2019</p> 80 </footer> 81 82 </div> <!-- /container --> 83 84 </body> 85</html>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/01/12 06:19
2019/01/12 07:21
2019/01/14 08:35