html - Bootstrap 似乎没有导入

标签 html css ruby-on-rails ruby twitter-bootstrap

我是 RoR 的新手,一直在关注 Michael Hartl 的教程,现在一直停留在介绍 Bootstrap 框架的部分。所有 gem 都在更新和安装。

locales/application.rb

require File.expand_path('../boot', __FILE__)

# Pick the frameworks you want:
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)

module SampleApp
  class Application < Rails::Application
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration should go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded.

    # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
    # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
    # config.time_zone = 'Central Time (US & Canada)'

    # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
    # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
    # config.i18n.default_locale = :de
     config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif) 
  end
end

application.html.erb

<!DOCTYPE html>
<html>
  <head>
    <title><%= full_title(yield(:title)) %></title>
    <%= stylesheet_link_tag "default", media: "all", "data-turbolinks-track" => true %>
    <%= javascript_include_tag "default", "data-turbolinks-track" => true %>
    <%= csrf_meta_tags %>
    <%= render 'layouts/shim' %>
  </head>
  <body>
    <%= render 'layouts/header' %>
    <div class="container">
      <%= yield %>
      <%= render 'layouts/footer' %>
    </div>
  </body>
</html>

home.html.erb

<% provide(:title, 'Home') %>

<div class="center hero-unit">
<h1>Welcome to the Sample App</h1>

<h2>
    This is the home page for the
    <a href="http://railstutorial.org/">Ruby on Rails Tutorial</a>
    sample application.
</h2>

<%= link_to "Sign up now!", '#', class: "bttn btn-large btn-primary" %>
</div>

<%= link_to image_tag("rails.png", alt: "Rails"), 'http://rubyonrails.org/' %>

自定义.css.scss

@import "bootstrap";

/* universal */

html    {
    overflow-y: scroll;
}

border-style: {
    padding-top: 60px;
}

section {
    overflow:auto;
}

textarea    {
    resize: vertical;
}

.center {
    text-align: center;
}

.center h1  {
    margin-bottom: 10px;
}

我收集到的很可能是不正确的事实是/home.html.erb 的源代码没有对/styles/bootscrap.css 进行任何引用。我应该有一个 bootstrap.css 文件和我的其他样式表吗?如果是这样,在图文中没有提到。

  <head>
    <title>Ruby on Rails Tutorial Sample App | Home</title>
    <link data-turbolinks-track="true" href="/stylesheets/default.css" media="all" rel="stylesheet" />
    <script data-turbolinks-track="true" src="/javascripts/default.js"></script>
    <meta content="authenticity_token" name="csrf-param" />
<meta content="n2QVul+/didf2xA6jj3QelpDZdOrUpgaWcDp1XFQACM=" name="csrf-token" />
    <!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<! [endif]

这就是/static_pages/home 对我来说的样子: my home

对比教程中的一个:tutorial home 我想不出还有什么要包括的,但如果我错过了什么,我一定会尽快跟进。谢谢!

最佳答案

在application.html.erb中, 它应该是“应用程序”,而不是“默认”。

<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>

https://github.com/railstutorial/sample_app_rails_4/blob/master/app/views/layouts/application.html.erb

关于html - Bootstrap 似乎没有导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20715418/

相关文章:

ruby-on-rails - Axlsx rails 。生成 .xlsx 文件并将文件名响应为 json/html

javascript - jQuery document.on() 子选择器

javascript - 加载程序在 ng-include 完成之前可见

jquery - 滚动条上的动画数字计数器

ruby-on-rails - 将文本字符串转换为任何有效的 Ruby 格式时间

mysql - 查找 sql/rails 中最受欢迎的日期

html - 悬停时菜单项移动

jQuery CSS 宽度属性在 Safari 上返回不一致

javascript - 创建警告框(jQuery、Bootstrap)但它一直消失

javascript - 具有相同定义的 Material ui多个类名