[英]Cannot integrate Bootstrap in my Ruby on Rails (version 4.0.0) app
我尝试了多种方法,遵循了许多教程,但是对我的Rails应用程序没有任何影响。 这是我的Gemfile:
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2'
gem 'paperclip', '~>3.0'
gem 'sass-rails', '~>4.0.0'
gem 'bootstrap-sass', '~>3.2.0.2'
gem 'autoprefixer-rails'
group :doc do
gem 'sdoc', require: false
end
application.css.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, vendor/assets/stylesheets,
* or vendor/assets/stylesheets of plugins, if any, 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 top of the
* compiled file, but it's generally better to create a new file per style scope.
*
*/
@import "bootstrap-sprockets";
@import "bootstrap";
application.js
文件:
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file.
//
// Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
// about supported directives.
//
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require_tree .
index.html.erb
文件:
<div class="posts index">
<h1>Welcome to The Incognito Social Network</h1>
<%=link_to("Say Something!", {:action=> 'new'}, :class=>'action new')%>
<table class="listing" summary="All posts">
<% @posts.each do |post| %>
<tr><td> </td></tr>
<tr>
<td>Post #<%=post.id%> </td>
<td><%=post.text%></td>
<%if post.image_file_name%>
<td>
<%=image_tag post.image.url %>
</td>
<%end%>
</tr>
<tr>
<td><%= link_to("Like", '#', :class=>'action upvote')%></td>
</tr>
<%end%>
</table>
</div>
我曾尝试在控制器中编写layout false
和#layout false
。 没有一个生效。
Rails应用程序没有任何变化。 我尝试将引导程序代码放入index.html.erb文件中,但引导程序样式中没有出现引导程序代码。 看起来好像它的简单HTML。 有人知道如何解决这个问题吗? 谢谢。
正如@vanburen已经写道:您必须将table
类添加到table
标记中。
所以更换
<table class="listing" summary="All posts">
与
<table class="table listing" summary="All posts">
现在,引导程序应该识别该表并更改其样式。
您将在“ 文档”中找到更多信息。
快乐编码:)。
好的,所以我安装了Node.js并重新启动了计算机。 而且这是我更新的Gemfile
source 'https://rubygems.org'
gem 'rails', '4.0.0'
gem 'mysql2','~> 0.3.11'
gem 'paperclip', '~>3.0'
gem 'sass-rails', '~>4.0.0'
gem 'bootstrap-sass', '~>3.2.0.2'
gem 'autoprefixer-rails'
gem 'acts_as_votable', '~>0.10.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
我还发现,必须使控制器中的layout false
注释掉才能使Bootstrap运行。 谢谢@Tobias和@vanburen的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.