我有一个基于Michael Hartl's tutorial的网站,但遗憾的是我在渲染特定的某个网页时遇到了问题。该页面名为/ games / new
以下是代码Games/new.html.erb
:
<h1>New game</h1>
<div class='div_left'>
<h2>Custom Game</h2>
<%= render 'fantasy' %>
</div>
<div class='div_right'>
<h2>Upcoming Games</h2>
<%= render 'real' %>
</div>
以下是custom.css.scss
的代码:
@import "bootstrap";
/* mixins, variables, etc. */
$grayMediumLight: #eaeaea;
@mixin box_sizing {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
/* universal */
p.big {
font-size:200%;
display:inline;
}
div.div_left {
width:400px;
float:left;
}
div.div_right {
width:400px;
float:right;
}
div.div_left_small {
width:175px;
float:left;
}
div.div_right_small {
width:175px;
float:right;
}
div.div_center {
width:400px;
float:right;
}
div.inline {
display:inline
}
html {
overflow-y: scroll;
}
body {
padding-top: 60px;
}
section {
overflow: auto;
}
textarea {
resize: vertical;
}
.center {
text-align: center;
h1 {
margin-bottom: 10px;
}
}
/* typography */
h1, h2, h3, h4, h5, h6 {
line-height: 1;
}
h1 {
font-size: 3em;
letter-spacing: -2px;
margin-bottom: 30px;
text-align: center;
}
h2 {
font-size: 1.7em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $grayLight;
}
p {
font-size: 1.1em;
line-height: 1.7em;
}
/* header */
#logo {
float: left;
margin-right: 10px;
font-size: 1.7em;
color: white;
text-transform: uppercase;
letter-spacing: -1px;
padding-top: 9px;
font-weight: bold;
line-height: 1;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $grayMediumLight;
color: $grayLight;
a {
color: $gray;
&:hover {
color: $grayDarker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 10px;
}
}
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}
/* sidebar */
aside {
section {
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:first-child {
border: 0;
padding-top: 0;
}
span {
display: block;
margin-bottom: 3px;
line-height: 1;
}
h1 {
font-size: 1.4em;
text-align: left;
letter-spacing: -1px;
margin-bottom: 3px;
margin-top: 0px;
}
}
}
.gravatar {
float: left;
margin-right: 10px;
}
.stats {
overflow: auto;
a {
float: left;
padding: 0 10px;
border-left: 1px solid $grayLighter;
color: gray;
&:first-child {
padding-left: 0;
border: 0;
}
&:hover {
text-decoration: none;
color: $blue;
}
}
strong {
display: block;
}
}
.user_avatars {
overflow: auto;
margin-top: 10px;
.gravatar {
margin: 1px 1px;
}
}
/* forms */
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
padding: 10px;
margin-bottom: 15px;
@include box_sizing;
}
input {
height: auto !important;
}
#error_explanation {
color:#f00;
ul {
list-style: none;
margin: 0 0 18px 0;
}
}
.field_with_errors {
@extend .control-group;
@extend .error;
}
/* users index */
.users {
list-style: none;
margin: 0;
li {
overflow: auto;
padding: 10px 0;
border-top: 1px solid $grayLighter;
&:last-child {
border-bottom: 1px solid $grayLighter;
}
}
}
/* microposts */
.microposts {
list-style: none;
margin: 10px 0 0 0;
li {
padding: 10px 0;
border-top: 1px solid #e8e8e8;
}
}
.content {
display: block;
}
.timestamp {
color: $grayLight;
}
aside {
textarea {
height: 100px;
margin-bottom: 5px;
}
}
以下是_fantasy.html.erb
的代码:
<%= simple_form_for(@game) do |f| %>
<div class='form-inputs'>
<%= f.error_notification %>
<% choices = Team.all.map { |team| team[:name] } %>
<%= f.input :first_team_name, collection: choices, label: 'Team 1' %>
<%= f.input :second_team_name, collection: choices, label: 'Team 2' %>
<%= f.input :user_guess, collection: [ 1, 2 ],
label_method: lambda { |obj| "Team #{ obj }"},
value_method: lambda { |obj| obj },
label: 'Who do you think will win?',
as: :radio_buttons%>
<%= f.input :game_type_id, :as => :hidden, :input_html => { :value => 1 } %>
<br>
<%= f.submit 'Simulate!', class: 'btn btn-large btn-primary'%>
</div>
<% end %>
以下是_real.html.erb的代码:
<%= simple_form_for(@game) do |f| %>
<div class='form-inputs'>
<% reference_games = Game.where(game_type_id: 3).map {
|game| [ "#{ game.first_team_name } vs #{ game.second_team_name }", game.date_played ] } %>
<%= f.input :team_names, collection: reference_games,
label_method: lambda { |obj| obj[0] },
value_method: lambda { |obj| "#{ obj[0] } vs #{ obj[1] }".gsub( ' vs ', ',' ) },
label: 'Choose a game' %>
<%= f.input :user_guess, collection: [ 1, 2 ],
label_method: lambda { |obj| "Team #{ obj }"},
value_method: lambda { |obj| obj },
label: 'Who do you think will win?',
as: :radio_buttons%>
<%= f.input :game_type_id, :as => :hidden, :input_html => { :value => 2 } %>
<br>
<%= f.submit 'Simulate!', class: 'btn btn-large btn-primary'%>
</div>
<% end %>
以下是application.html.erb
的代码:
<!DOCTYPE html>
<html>
<head>
<link rel="shortcut icon" href="/favicon.ico" />
<!--#<title><%= full_title(yield(:title)) %></title> #TODO: Make custom titles work-->
<title>Shoulak Predictions</title>
<%= stylesheet_link_tag "application", media: "all" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<% flash.each do |key, value| %>
<div class="alert alert-<%= key %>"><%= value %></div>
<% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>
最后,这是_footer.html.erb
的代码:
<footer class="footer">
<nav>
<ul>
<li><%= link_to "About", about_path, class: "class1" %></li>
<li><%= link_to "Contact", contact_path, class: "class1 " %></li>
</ul>
</nav>
</footer>
答案 0 :(得分:1)
将页脚渲染移到“容器”div
</div>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</body>