【发布时间】:2020-01-31 05:09:37
【问题描述】:
我的链接不适用于我的 ruby on rails 网站。当我单击该链接时,该站点将停留在同一页面上。我正在遵循一本书中的代码:“RailsSpace:在 Rails 上使用 ruby 构建社交网站”,作者 Michael Hartl。这本书可以免费下载,您可以自己按照代码进行操作,它位于第 55-56 页,从标题“添加导航”开始。这是ebook 的链接。
感谢您的帮助。
我尝试用谷歌搜索“link_to”函数并更改格式,它所做的只是产生更多错误,请帮忙。
这是我的 app/views/layout/site.html.erb 文件中的代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title><%= @title %></title>
<%= stylesheet_link_tag "site" %>
</head>
<body>
<div id="whole_page">
<div id="header">RailsSpace</div>
<div id="nav">
<%= link_to_unless_current "Home", :action => "index" %> |
<%= link_to "About Us" , :action => "help" %> |
<%= link_to_unless_current "Help", :action => "help" %>
<div style="background-color:white">
<h1>Welcome to RailSpace!</h1>
<p>This is going to be the best site ever!</p>
</div>
</div>
<div id="content">
<%= @content_for_layout %>
</div>
</div>
</body>
</html>
这是我的 app/controllers/site_controller.rb 文件的代码:
class SiteController < ApplicationController
def index
@title = "Welcome to RailsSpace!"
end
def about
@title = "About RailsSpace"
@header = "Hello"
end
def help
@title = "RailsSpace Help"
end
end
这是我的 config/routes.rb 文件的代码:
Rails.application.routes.draw do
get 'site/index'
get '/site/about'
get 'site/help'
root 'site#index'
// 这是我按要求点击链接时控制台的输出:
Started GET "/site/about" for ::1 at 2019-10-01 15:28:48 -0700
Processing by SiteController#about as HTML
Rendering site/about.html.erb within layouts/site
Rendered site/about.html.erb within layouts/site (Duration: 0.0ms |
Allocations: 5)
Completed 200 OK in 7ms (Views: 6.8ms | ActiveRecord: 0.0ms |
Allocations: 2921)
感谢大家的帮助
当我点击导航栏中的链接时,网站停留在同一页面上。请帮忙。
【问题讨论】:
-
我重新发布了相同的问题,因此我可以包含另外两个文件中的代码。我不知道如何编辑我已经提出的问题。
-
标签正下方有一个
edit链接。 -
哈哈,天哪,我没看到,我以为它都是闪亮的蓝色。谢谢。
-
请在您单击链接时将控制台的输出添加到您的问题中。
标签: ruby-on-rails hyperlink controller link-to