質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Bootstrap

BootstrapはウェブサイトデザインやUIのWebアプリケーションを素早く 作成する可能なCSSフレームワークです。 Twitter風のデザインを作成することができます。

Q&A

解決済

1回答

3930閲覧

railsへbootstrapの導入について

ma-------ro

総合スコア8

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Bootstrap

BootstrapはウェブサイトデザインやUIのWebアプリケーションを素早く 作成する可能なCSSフレームワークです。 Twitter風のデザインを作成することができます。

0グッド

0クリップ

投稿2020/07/06 15:07

railsへbootstrapの導入について

このサイトでも多くの人が質問をしている内容のようでして、何件か他の人の質問を下に試してみたのですが、どうしてもエラーが解除されないため、質問をさせていただきます。
railsにbootstrapを導入しようとすると、エラーとなってしまいます。
エラーの解除方法を教えてください。

エラー内容

SassC::SyntaxError in Articles#index

Showing /Users/kurosawaminoruhiroshi/Desktop/weblog/app/views/layouts/application.html.erb where line #8 raised:

Error: File to import not found or unreadable: bootstrap-sprockets.
on line 14:2 of app/assets/stylesheets/application.scss

@import "bootstrap-sprockets";

*/
@import "bootstrap-sprockets";
@import "bootstrap";

#gemfile source 'https://rubygems.org' git_source(:github) { |repo| "https://github.com/#{repo}.git" } ruby '2.6.3' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 6.0.3', '>= 6.0.3.2' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.4' # Use Puma as the app server gem 'puma', '~> 4.1' # Use SCSS for stylesheets gem 'sass-rails', '>= 6' # Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker gem 'webpacker', '~> 4.0' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder gem 'jbuilder', '~> 2.7' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use Active Model has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Active Storage variant # gem 'image_processing', '~> 1.2' # Reduces boot times through caching; required in config/boot.rb gem 'bootsnap', '>= 1.4.2', require: false gem 'bootstrap-sass', '~> 3.4.1' gem 'sassc-rails', '>= 2.1.0' gem 'jquery-rails' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] end group :development do # Access an interactive console on exception pages or by calling 'console' anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '~> 3.2' # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring gem 'spring' gem 'spring-watcher-listen', '~> 2.0.0' end group :test do # Adds support for Capybara system testing and selenium driver gem 'capybara', '>= 2.15' gem 'selenium-webdriver' # Easy installation and use of web drivers to run system tests with browsers gem 'webdrivers' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
#application.scss /* * This is a manifest file that'll be compiled into application.css, which will include all the files * listed below. * * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's * vendor/assets/stylesheets directory can be referenced here using a relative path. * * You're free to add application-wide styles to this file and they'll appear at the bottom of the * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS * files in this directory. Styles in this file should be added after the last require_* statement. * It is generally better to create a new file per style scope. * */ @import "bootstrap-sprockets"; @import "bootstrap";
#application.js // This file is automatically compiled by Webpack, along with any other files // present in this directory. You're encouraged to place your actual application logic in // a relevant structure within app/javascript and only use these pack files to reference // that code so it'll be compiled. //= require jquery //= require bootstrap-sprockets // Uncomment to copy all static images under ../images to the output folder and reference // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>) // or the `imagePath` JavaScript helper below. // // const images = require.context('../images', true) // const imagePath = (name) => images(name, true)

参考サイト
https://github.com/twbs/bootstrap-sass

試したこと
rails s
上記サイトに沿って導入の準備

よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

okina

2020/07/06 15:21

Cloud9で発生してたりしますか?
ma-------ro

2020/07/06 15:52

使用しているのはVsCodeです!
m.ts10806

2020/07/06 22:47

その何件か参考にした質問URLをリンクで提示してください。
m.ts10806

2020/07/07 12:15

質問は編集できますので本文に追記願います
guest

回答1

0

ベストアンサー

jQueryの導入方法が、Rails5からRails6にかけて導入方法が大きく異なります。
これは標準のモジュールバンドラがSprocketsからWebpackerになったためです。

Rails6であれば下記の「Webpackerで入れる場合」に沿って実装いただくのがスムーズかと思います。
https://qiita.com/kazutosato/items/d47b7705ee545de4cb1a

またgemfileを見る限り開発スタートして間もないと思うので、現在のアプリを削除するなりして、最初からやり直すことをおすすめします。


Rails5まではリンク先の「assetsに入れる場合」(Sprockets)が標準的な実装方法でしたが、今後は「Webpackerで入れる場合」のやり方が主流になっていくので、こちらを推薦します。

投稿2020/07/07 12:30

no1knows

総合スコア3365

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ma-------ro

2020/07/08 12:55

どうもありがとうございます。 本日1から作り直し、bootstrapの設定をしたところ、1回でエラーなく設定することができました。 本当にありがとうございました。
no1knows

2020/07/09 09:32

それは良かったです!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問