gpt4 book ai didi

css - 在 Ruby 的 Cuba 框架中链接样式表

转载 作者:数据小太阳 更新时间:2023-10-29 08:02:59 28 4
gpt4 key购买 nike

这看起来应该很简单,但我不知道如何获得链接 stylesheeterb Cuba 中的模板应用程序。

hello_world.rb

require "cuba"
require "cuba/safe"
require "cuba/render"
require "erb"

Cuba.use Rack::Session::Cookie, :secret => "__a_very_long_string__"

Cuba.plugin Cuba::Safe
Cuba.plugin Cuba::Render

Cuba.define do
on root do
res.write view("home")
end
end

views/layout.erb

<!DOCTYPE html>
<html lang="en">

<head>
<link href="styles/basic.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div>
<h1>Hello</h1>
</div>
</body
</html>

config.ru

require "./hello_world"
run Cuba

styles/basic.css

h1 {
font-size: 128px;
}

div {
padding: 50px;
margin: 100px;
}

我试过使用一些 Sinatra标准就像把我的 css在名为 public 的目录中以及使用 <link href="<%= url('styles/basic.css') %>" rel="stylesheet" type="text/css" />但没有任何效果。

最佳答案

古巴不提供静态 Assets 。您可以为此使用 Rack::Static:

# hellow_world.rb
Cuba.use Rack::Static,
root: "public",
urls: ["/javascripts", "/css", "/images"]

然后,在您的 View 中引用此文件夹。

# layout.erb
<link href="/public/css/basic.css" rel="stylesheet" type="text/css" />

关于css - 在 Ruby 的 Cuba 框架中链接样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37996579/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com