css - 无法将 Bootstrap 集成到我的 Ruby on Rails(版本 4.0.0)应用程序中

标签 css ruby-on-rails twitter-bootstrap ruby-on-rails-4 rubygems

我尝试了多种方法,遵循了很多教程,但对我的 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>&nbsp</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>

我尝试在我的 Controller 中编写 layout false#layout false。没有一个生效。

Rails 应用程序没有任何变化。我尝试将 Bootstrap 代码放入我的 index.html.erb 文件中,但它没有以 Bootstrap 样式出现。它看起来好像是简单的 HTML。有人知道如何解决这个问题吗? 谢谢。

最佳答案

正如@vanburen 已经写过的:您必须将 table 类添加到您的 table 标签中。

所以替换

<table class="listing" summary="All posts">

<table class="table listing" summary="All posts">

现在 bootstrap 应该可以识别表格并改变它的样式。

您将在 Docs 中找到更多信息.

快乐编码:).

关于css - 无法将 Bootstrap 集成到我的 Ruby on Rails(版本 4.0.0)应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253621/

相关文章:

ruby-on-rails - 如何在 Rails 4 中使用单个和多个资源路由?

html - 如何以不太具体的方式更改 Bootstrap table-striped?

css - 使用背景图像将 LESS Bootstrap mixin 添加到 body

css - 将所有 CSS 合并到一个文件中还是动态加载?

ruby-on-rails - 如何在 Rails 5 中的现有表中添加新列?

html - div 的文本和边框之间的空格,为什么?

ruby-on-rails - 无法从公共(public) IP 连接到 EC2 上运行的 Rails 服务器

javascript - 如何使我的导航栏(具有透明背景)在视差滚动网页中 float /重叠我的背景?

jquery - 过滤掉包含多个 css 类的 tr

css - 如何删除具有特定前缀的所有类(使用 Visual Studio Code)?