小编And*_*dov的帖子

Ruby/Rails:使用`separator:' - '`代替

为我的项目编写测试,并在运行rspec时注意这个警告它终端

DEPRECATION WARNING: Passing the separator argument as a positional
parameter is deprecated and will soon be removed. 
Use `separator: '-'` instead.
(called from add_link at /myapp/app/models/post.rb:37)
Run Code Online (Sandbox Code Playgroud)

我在保存记录之前有一个动作,看起来像

self.link = theme + '-' + Time.now.to_formatted_s(:number)
Run Code Online (Sandbox Code Playgroud)

我试图找到一些关于此的信息,但我真的不明白这个警告意味着什么.

**编辑**

好吧,我改变了"#{theme}-#{Time.now.to_formatted_s(:number)}"但它仍然给了我同样的警告.

比我决定走另一条路而改变了"#{theme}(#{date})".该date方法是这样的:

date = [Time.now.day, Time.now.month, Time.now.year]
date = date.join('-')
date
Run Code Online (Sandbox Code Playgroud)

但它仍然给我一个错误.

我不认为这是一个很大的问题,但我仍然想知道为什么会发生这种情况.

**编辑**

弄清楚,它必须使用的宝石导致该问题(宝石被调用the_string_to_slug)我将做未来的研究来修复这个警告与宝石或我将试图找到替换它的方法.

ruby ruby-on-rails

8
推荐指数
1
解决办法
717
查看次数

HTML,flex,连续两个div,强制一个div的尺寸变小

主语

我有两个 div(左和右)。我想让左边的 div 像主要的一样,并强制右边的 div 与左边的高度相同,即使它会有更多的内容(并且这样做overflow: hidden)。如果有一种方法可以使用csshtml不使用它,我将不胜感激js

这是一个小片段,我的标记看起来如何:

.parent {
  display: flex;
  flex-direction: row;
  align-items: stretch;
}

.children-1 {
  width: 66.6%;
  background: green;
}

.children-2 {
  width: 33.4%;
  background: yellow;
}
Run Code Online (Sandbox Code Playgroud)
<div class="parent">
  <div class="children-1">
    <p>My content</p>
  </div>
  
  <div class="children-2">
    <p>a lot of content<p>
    <p>a lot of content</p>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

html css flexbox

5
推荐指数
1
解决办法
7562
查看次数

HTML 预加载字体并在 css 中使用它

我知道你们都知道,如果我们在 .css 文件中这样做:

@font-face {
        font-family: "Akrobat-Regular";
        src: url('/assets/Akrobat-Regular.otf') format("truetype");
      }
      body {
        color: #1c1c1c;
        font-family: "Akrobat-Regular" !important;
      }
Run Code Online (Sandbox Code Playgroud)

浏览器将发出额外的下载字体请求,因此将在短时间内使用默认字体,然后将其替换为新下载的字体。

我找到了这种预加载字体的方法,但真的不知道如何在没有额外请求的情况下使用下载的字体(不用担心,ti as slim 语法):

    link rel='preload' href='/assets/Akrobat-Regular.otf' as='font' type='font/otf'

    = stylesheet_link_tag 'application'

    css:
      @font-face {
        font-family: "Akrobat-Regular";
        src: url('/assets/Akrobat-Regular.otf') format("truetype");
      }
      body {
        color: #1c1c1c;
        font-family: "Akrobat-Regular" !important;
      }
Run Code Online (Sandbox Code Playgroud)

html css fonts

3
推荐指数
1
解决办法
8342
查看次数

从DB中选择没有值

我有自己的rails应用程序,我需要指定我想从DB(pg)获得什么.普通的,我们这样做:@posts = Post.all我将在Post Table中获得所有帖子.

在帖子表中,我有一个类别,作为布尔值:(照片,视频等),当我想只选择帖子对照片类别的响应时,我们这样做: @posts = Post.where(photo: true)

但我需要的是选择所有帖子,例如视频.它必须看起来像这样:@posts = Post.all.without(video:true).如何实现?

更新

有没有可能阻止几个值?我的意思是这样的Post.where.not(id: 1 && 2).我真的不知道它的样子.我需要的是选择没有ID为1和2的帖子的所有帖子.

ruby database postgresql ruby-on-rails

0
推荐指数
1
解决办法
53
查看次数

标签 统计

css ×2

html ×2

ruby ×2

ruby-on-rails ×2

database ×1

flexbox ×1

fonts ×1

postgresql ×1