我有三个类似的函数,他们过滤一组与键(列)匹配的映射与其值,不区分大小写.
这是我想要干的原始代码:
;; gets a collection filtered by a column, exact match
(defn get-collection-by-equals [collection-name column-name column-value]
(filter #(= (string/lower-case (column-name %)) (string/lower-case column-value)) (cached-get-collection collection-name)))
;; gets a collection filtered by a column, with partial match, case-insensitive
(defn get-collection-by-like [collection-name column-name column-value]
(filter #(string/includes? (string/lower-case (column-name %)) (string/lower-case column-value)) (cached-get-collection collection-name)))
;; gets a collection filtered by a column, which starts with given value, case-insensitive
(defn get-collection-by-starts-with [collection-name column-name column-value]
(filter #(string/starts-with? (string/lower-case (column-name %)) (string/lower-case column-value)) (cached-get-collection collection-name))) …Run Code Online (Sandbox Code Playgroud) 我正在实施一个登录系统。我创建了用户模型,但该方法有问题#before_create。SystemStackError (stack level too deep)在 Rails 控制台中创建新用户时,它总是会引发错误,如下所示:
User.create(name:"othman", email: "othman@gmail.com", password: "12345678", password_confirmation: "12345678" )"
Run Code Online (Sandbox Code Playgroud)
我正在使用 ruby on Rails 实现登录系统,在创建新用户之前我需要记住用户令牌。
用户模型代码:
require 'digest'
class User < ApplicationRecord
attr_accessor :token
before_create remember
validates :name, presence: true
validates :email, presence: true
has_secure_password
validates :password, presence: true, length: { minimum: 6 }
def remember
self.token = User.new_token
update_attribute(:remember_digest , User.create_digest(token))
end
def User.new_token
SecureRandom.urlsafe_base64
end
def User.create_digest(string)
Digest::SHA1.hexdigest string
end
end
Run Code Online (Sandbox Code Playgroud)
错误信息:
irb(main):017:0> user1 = User.create(name:"othman", email: "othman@gmail.com", password: …Run Code Online (Sandbox Code Playgroud) 我在 Ruby 功能规范中使用 Capybara 的Cuprite驱动程序。
Chrome process did not produce websocket url within 2 seconds当规范在我们的 CI 服务器上运行时,规范在本地运行良好,但会失败并出现错误。CI 服务器在 Docker 容器中运行规范。
Docker 映像从 Google PPA 安装最新版本的 Chrome 77.0。
使用ActionMailer时,它在常规路径中使用"视图",但是如何配置正在使用的"视图"(即选择自己的)?
看起来很容易改变正在使用的'布局',但是你在视图中做同样的事情?
我很确定我需要一个有效的多规格。但是我不确定如何说作为向量的键值可以包含异构映射。
我是我要规范的源数据:
(def int-attr { :type "int" :validations [{ :min 0 } { :max 100 }] })
(def string-attr { :type "string" :validations [{ :presence true }] })
Run Code Online (Sandbox Code Playgroud)
这是validations我遇到问题的type钥匙,取决于钥匙,"int"或者"string",我想要validations钥匙中的不同规格。
我很确定我必须使用multi-spec. 这是我尝试过的:
(defmulti attribute-type :type)
(defmethod attribute-type "string" [a] ::string-validations)
(defmethod attribute-type "int" [a] ::int-validations)
;; how to say this is a vector of int-min-validation, or int-max-validation etc.
;; (s/+ ...) and (s/or ...) maybe?
(s/def ::int-validations (...)
(s/def …Run Code Online (Sandbox Code Playgroud) 我做bundle install了,mysql2 gem从0.4.10更新到0.5.0.
在此之后,涉及ActiveRecord的任何事情都会因标题中的错误而爆炸.