迈克尔·哈特尔教程 - 第 7 章调试器未显示



我一直在努力弄清楚为什么调试器不会显示。尽管没有让这部分工作,我还是决定继续前进。但是后来我也无法让/users/1 显示任何信息,即使路线似乎有效......

所以现在我要回到最初的问题,谁能告诉我在哪里仔细检查为什么不显示?

但是,我也包含了与我的第二个问题有关的代码 - 让用户/1 显示预期的信息

rails 控制台使用 User.first 正确显示用户

应用程序.html.erb

<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= csrf_meta_tags %>
<%= stylesheet_link_tag    'application', media: 'all',
'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
</div>
</body>
</html>

custom.scss

@import "bootstrap-sprockets";
@import "bootstrap";
/* mixins, variables, etc. */
$gray-medium-light: #eaeaea;
@mixin box_sizing {
-moz-box-sizing:    border-box;
-webkit-box-sizing: border-box;
box-sizing:         border-box;
}

/* universal */
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.2em;
letter-spacing: -1px;
margin-bottom: 30px;
text-align: center;
font-weight: normal;
color: $gray-light;
}
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;
&:hover {
color: white;
text-decoration: none;
}
}
/* footer */
footer {
margin-top: 45px;
padding-top: 5px;
border-top: 1px solid $gray-medium-light;
color: $gray-light;
a {
color: $gray;
&:hover {
color: $gray-darker;
}
}
small {
float: left;
}
ul {
float: right;
list-style: none;
li {
float: left;
margin-left: 15px;
}
}
}
/* miscellaneous */
.debug_dump {
clear: both;
float: left;
width: 100%;
margin-top: 45px;
@include box_sizing;
}

路线.rb

Rails.application.routes.draw do
get 'users/new'
root 'static_pages#home'        
get '/help', to: 'static_pages#help'
get '/about', to: 'static_pages#about'
get '/contact', to: 'static_pages#contact'
get '/signup',  to: 'users#new'
resources :users
end

views/users/show.html.erb

<%= @user.name %>, <%= @user.email %>
<h1>
<%= gravatar_for @user %>
<%= @user.name %>
</h1>

用户控制器 - users_controller.rb

class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
end
end

谢谢

如果 Rails.env.development? %> 将 "application.html.erb" 中的调试行修改为
<%= debug(params.to_yaml)</p> </div> </html>%>

最新更新