RailsでBootstrapを導入しようとしているのですが、上手く動きません。
色々試したのですが、エラーが出たり、読み込むクラスと読み込まないクラスがあったり、またサイトによってjqueryを入れたり、入れなかったり、application.scssに@import "bootstrap-sprockets";を入れたり入れなかったりしていて、色々なパターンで試したのですが、上手く動きません。(なぜかclass="btn btn-primary"は反映されるのにclass="navbar-default"は反映されないということが起きたりしました。)
混乱してよくわからなくなってしまったので、アドバイス頂けると幸いです。
よろしくお願いします。
環境
Mac OS high sierra 10.13.6
ruby 2.5.1
rails 5.1.6
htm
1<!DOCTYPE html> 2<html> 3 <head> 4 <meta charset="utf-8"> 5 <title>AwesomeEvents</title> 6 <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 7 <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 8 <%= csrf_meta_tags %> 9 </head> 10 <body> 11 <header class="navbar navbar-default"> 12 <button class="btn btn-primary" type="button" name="button">button</button> 13 </body> 14</html>
#gemfile source 'https://rubygems.org' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.6' # Use sqlite3 as the database for Active Record gem 'sqlite3' # Use Puma as the app server gem 'puma', '~> 3.7' # Use SCSS for stylesheets gem 'sass-rails' gem 'bootstrap', '~> 4.1.1' gem 'bootstrap-sass' gem 'jquery-rails' # Use Uglifier as compressor for JavaScript assets gem 'uglifier', '>= 1.3.0' # See https://github.com/rails/execjs#readme for more supported runtimes # gem 'therubyracer', platforms: :ruby gem 'slim-rails' gem 'html2slim' gem 'omniauth' gem 'omniauth-twitter' # Use CoffeeScript for .coffee assets and views gem 'coffee-rails', '~> 4.2' # 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.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 4.0' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development 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 IRB console on exception pages or by using <%= console %> anywhere in the code. gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 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 # Windows does not include zoneinfo files, so bundle the tzinfo-data gem gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
scss
1#application.scss 2@import "bootstrap"; 3 4/* 5 * This is a manifest file that'll be compiled into application.css, which will include all the files 6 * listed below. 7 * 8 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's 9 * vendor/assets/stylesheets directory can be referenced here using a relative path. 10 * 11 * You're free to add application-wide styles to this file and they'll appear at the bottom of the 12 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS 13 * files in this directory. Styles in this file should be added after the last require_* statement. 14 * It is generally better to create a new file per style scope. 15 * 16 17 */ 18
javascript
1#application.js 2 3 4// This is a manifest file that'll be compiled into application.js, which will include all the files 5// listed below. 6// 7// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's 8// vendor/assets/javascripts directory can be referenced here using a relative path. 9// 10// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 11// compiled file. JavaScript code in this file should be added after the last require_* statement. 12// 13// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details 14// about supported directives. 15// 16// 17//= require rails-ujs 18//= require jquery 19//= require bootstrap-sprockets 20//= require turbolinks 21//= require_tree . 22 23
回答1件
あなたの回答
tips
プレビュー