Railsnoob在这里。 Bootstrap崩溃在我的应用程序中无法正常工作。我在一个全新创建的rails应用程序中尝试了它,但它也无法正常工作:
My Gemfile如下所示:
source 'https://rubygems.org'
gem 'rails'
gem 'bootstrap-sass'
gem 'puma'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'sqlite3'
gem 'byebug'
end
group :development do
gem 'web-console'
gem 'listen'
gem 'spring'
gem 'spring-watcher-listen'
end
group :test do
gem 'rails-controller-testing'
gem 'minitest-reporters'
gem 'guard'
gem 'guard-minitest'
end
group :production do
gem 'pg'
end
应用程序/资产/样式表/ custom.scss:
@import "bootstrap-sprockets";
@import "bootstrap";
应用程序/视图/页/ home.html.erb 它包含bootstrap折叠文档的第一个示例:
<h1>Pages#home</h1>
<p>Find me in app/views/pages/home.html.erb</p>
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Link with href
</a>
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
Button with data-target
</button>
</p>
<div class="collapse" id="collapseExample">
<div class="card card-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
</div>
</div>
我无法弄清楚为什么它不起作用。我错过了一颗宝石吗?
编辑:找到解决方案,感谢Ishwar Deoolkar:)
我在头部添加了以下行:
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
和身体末端的这一行:
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
答案 0 :(得分:1)
您是否在项目文件夹中包含了bootstrap.js和jquery.js
Bootstrap Js:https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js“ Jquery Js:https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js“
同样的问题是进入我的代码,手风琴由于bootstrap而无法正常工作。但是在我的项目文件夹中包含上面的链接后,它对我有用。试试这个