AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-284257

Sig's questions

Martin Hope
Sig
Asked: 2025-04-15 20:23:22 +0800 CST

来自关联的 Active Record 计数组

  • 6

我可以使用 ActiveRecord 获得以下 SQL 查询的相同输出吗?

SELECT d.title, COUNT(ep.*)
FROM posts d
LEFT JOIN comments ep
ON d.title = ep.post_title
GROUP BY d.title;

我试过Post.joins(:comments).group(:title).count('comments.*')。

ruby-on-rails
  • 1 个回答
  • 39 Views
Martin Hope
Sig
Asked: 2025-02-09 00:46:09 +0800 CST

使用 TailwindCSS 独立 CLI

  • 6

我已经下载了最新的(v4.0.4)TailwindCSS 独立 CLI 并创建了以下文件。

tailwind.config.js

module.exports = {
  content: ["./index.html"],
  theme: {
    extend: {},
  },
  plugins: [],
}

tailwind.css

@tailwind base;
@tailwind components;
@tailwind utilities;

索引.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <p class="text-emerald-400 text-5xl font-bold">Lorem Ipsum</p>
  </body>
</html>

我开始用

./tailwindcss -i tailwind.css -o style.css --watch
≈ tailwindcss v4.0.4

Done in 41ms

但是,style.css我的页面中不包含样式index.html。

样式.css

/*! tailwindcss v4.0.4 | MIT License | https://tailwindcss.com */
.relative {
  position: relative;
}
.mx-auto {
  margin-inline: auto;
}
.flex {
  display: flex;
}
.inline-flex {
  display: inline-flex;
}
.w-full {
  width: 100%;
}
.flex-col {
  flex-direction: column;
}
.items-center {
  align-items: center;
}
.justify-center {
  justify-content: center;
}
.justify-end {
  justify-content: flex-end;
}
.justify-start {
  justify-content: flex-start;
}
.object-cover {
  object-fit: cover;
}
.text-center {
  text-align: center;
}
.transition-all {
  transition-property: all;
  transition-timing-function: var(--tw-ease, ease);
  transition-duration: var(--tw-duration, 0s);
}
.duration-700 {
  --tw-duration: 700ms;
  transition-duration: 700ms;
}
@property --tw-duration {
  syntax: "*";
  inherits: false;
}

我在这里遗漏了什么?

tailwind-css
  • 1 个回答
  • 31 Views
Martin Hope
Sig
Asked: 2025-02-06 23:38:34 +0800 CST

从模块内部访问类常量

  • 6

我需要从 Rails 应用程序中包含的模块访问 ActiveRecord 常量。

class User < ApplicationRecord
  include ModOne
  
  OPTIONS = {a: 1}.freeze

  ...
end
Module ModOne
  extend ActiveSupport::Concern

  included do
    do_semething(self::OPTIONS)
  end

  class_methods do
   def do_something(opts)
     ...
   end
  end
end

但我明白

NameError: 未初始化常量 User(调用“User.connection”建立连接)::OPTIONS 您是指?User::OPTIONS

我在这里遗漏了什么?

我也尝试过self用base_class和事件来替换User但是出现了同样的错误。

ruby-on-rails
  • 1 个回答
  • 70 Views
Martin Hope
Sig
Asked: 2024-02-05 23:05:29 +0800 CST

符号之间的匹配字符串

  • 6

这几天我一直在试图解决这个问题,但我无法让它发挥作用。我已经在 Stack-overflow 上查看了很多问题,但仍然无法找出解决它的正确方法。

我有表示带有数字和“多字”变量的算术表达式的字符串,例如(Car speed / Road-congestion Time) + 100和 我需要匹配除 之外的所有内容+-*/()。

我需要获得以下三场比赛:

  • 车速
  • 道路拥堵时间
  • 100

以下表达式类型适用[+-\\*\\/()]?([^+-\\*\\/()]*)[+-\\*\\/()]?于“多单词”变量中没有连字符的字符串(它在末尾添加了一个额外的空匹配)。为了区分减号和连字符,减号总是被空格包围,但我不知道如何在正则表达式中指定它。

有什么想法如何更新我的正则表达式以适应所有情况吗?另外,正则表达式应该忽略数字(仅获取上例中的前两个匹配项)。

PS - 拆分是最后一个选项,如果可能的话我想使用正则表达式。

regex
  • 1 个回答
  • 50 Views
Martin Hope
Sig
Asked: 2024-01-07 18:21:25 +0800 CST

辅助方法不呈现任何列表项

  • 5

在 Rails 7 中,为什么以下助手不渲染列表项?

def list(options)
  tag.ul(class: "a") do
    options.each do |option|
      tag.li(class: "b") do
        tag.span(option, class: "c")
      end
    end
  end
end

我打电话<%= list(["X", "Y", "Z"]) %>,渲染的很简单 <ul class="a"></ul>。

我在这里缺少什么?

ruby-on-rails
  • 1 个回答
  • 35 Views
Martin Hope
Sig
Asked: 2024-01-03 22:15:35 +0800 CST

检查数组的所有元素是否方向交替

  • 5

在 Ruby 中,我需要检查数组的所有元素是否在方向上交替,即前驱和后继是否大于或小于每个元素。

给出以下数组,结果必须如所示

[1,3,2,4,3]  # => true
[3,2,4,3,5]  # => true
[1,2,3,1,3]. # => false 
[1,2,2,1,3]. # => false

我得出了以下代码,它似乎有效,但它很漂亮或易于理解。

array.each_cons(2)     # get subsequent couple of items
  .map {|a,b| b-a}.    # get the difference between first and second
  .map {|n| n <=> 0}   # get the sign (-1/+1)
  .each_cons(2)        # get couple of signs
  .map {|a,b| a+b}     # sum each couple
  .uniq == [0]         # return true if all the couple are 0

有什么建议如何简化检查吗?

ruby
  • 2 个回答
  • 72 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve