我有2个属性id(字符串,主键),值(字符串).当我尝试使用KeyConditionExpression时,它会抛出不支持的查询键条件.
KeyConditionExpression: "begins_with(ID, :tagIDValue)"
or
KeyConditionExpression: "contains(ID, :tagIDValue)"
Run Code Online (Sandbox Code Playgroud)
从这个链接我知道我们只能在主键上使用EQ操作.我怎样才能做到这一点
解决方案:================================================ ======
我需要使用starts_with或contains来过滤所以我采用了以下方法.
表属性:PK(partion_key,string),ID(排序键,字符串),值(字符串).
现在我的主键是基于PK,ID构建的
PK将具有所有行的常量值.所以KeyConditionExpression就像.
KeyConditionExpression: "PL = :pk and begins_with(ID, :tagIDValue)"
Run Code Online (Sandbox Code Playgroud)
注意:但仍然包含不使用KeyConditionExpression.我认为它已从KeyConditionExpression中删除
这是一个正则表达式模式:
(@location =~ /\A#[a-zA-Z0-9]*\Z/) == 0
Run Code Online (Sandbox Code Playgroud)
RuboCop建议使用.zero?
而不是 == 0
.但是当正则表达式不匹配时,它将返回nil
.然后,nil.zero?
将抛出一个"未定义的方法.zero?
的nil
错误".有没有更好的方法在红宝石中做正则表达式?
嗨,我正在尝试在生产模式下的docker内部运行rails应用程序。它抛出错误以下。
Message from application: Invalid option key: raise_on_unfiltered_parameters= (RuntimeError)
Run Code Online (Sandbox Code Playgroud)
因此,我的应用程序服务器未启动,并且出现错误页面。
Dockerfile:
FROM docker.aws.com:443/consumertech/ruby-nginx-lua-anti-scrape:latest
# copy app source
RUN mkdir -p /data/app/my-app
RUN mkdir -p /data/app/my-app/log
RUN mkdir -p /data/app/my-app/tmp
RUN touch /data/app/my-app/dockerized
WORKDIR /data/app/my-app
ARG rails_env
ENV BUILD_ENV $rails_env
COPY . /data/app/my-app
RUN gem install bundler
RUN bundle install --with="production development test"
RUN RAILS_ENV=development bundle exec rake assets:precompile
ENV RAILS_ENV $rails_env
ENV NEW_RELIC_KEY "41dfc2f90fb480fbd4d2df35b77fffde68e42c74"
# unicorn
EXPOSE 3000
# need to start both unicorn and nscd
RUN echo "#!/usr/bin/env sh …
Run Code Online (Sandbox Code Playgroud) 从字符串数组我需要得到以age开头的字符串 - 后跟最多2位数字和可选的"+"符号.
例如:1岁,22岁,55岁,1岁以上,15岁以上
以下是我的阵列:
arr = ["vintage-colllections","age-5"]
or
arr = ["vintage-colllections","age-51+"]
Run Code Online (Sandbox Code Playgroud)
我将从阵列中提取年龄"年龄-5"或"年龄51岁".
我试过以下事情:
arr.find {|e| e.include?"age-"}
Run Code Online (Sandbox Code Playgroud)
适用于其他场景,但在数组的第一个元素上面还包括(vint)年龄失败.
arr.find { |e| /age-\d*\+?/ =~ e}
Run Code Online (Sandbox Code Playgroud)
工作正常,但我试图避免正则表达式.
还有其他更好的方法吗?欢迎任何建议.