我是RoR的新手,并且一直关注Michael Hartl的教程,现在已经停留在引入Bootstrap框架的部分。所有宝石都在更新和安装。
区域设置/ 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/' %>
custom.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文件和我的其他样式表吗?如果是这样,那就没有在tut中提到。
<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
VS。教程中的那个:tutorial home 我想不出任何其他要包括但如果我错过了什么,我一定会很快跟进。谢谢!
答案 0 :(得分:0)
在application.html.erb中, 它应该是“应用程序”,而不是“默认”。
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>