如何对OR逻辑进行条件验证,我们检查是否存在2个值中的1个或两个值是否存在.
因此,举例来说,如果我要检查,以确保email
或mobile
字段填写...我希望能够传递一个列表到fields
的validate_required_inclusion
验证,在列表中的字段的至少1个不为空.
def changeset(struct, params \\ %{}) do
struct
|> cast(params, [:email, :first_name, :last_name, :password_hash, :role, :birthdate, :address1, :address2, :city, :state, :zip, :status, :mobile, :card, :sms_code, :status])
|> validate_required_inclusion([:email , :mobile])
end
def validate_required_inclusion(changeset, fields, options \\ []) do
end
Run Code Online (Sandbox Code Playgroud)
我该如何进行有条件的OR验证?
如何列出我的元素yml
并在视图中循环它们并访问它们的属性?我当前的代码只获取列表中的最后一项.我想在视图中循环遍历项目列表并显示它们title
和description
元素.
例如
阳明:
en:
hello: "Hello world"
front_page:
index:
description_section:
title: "MyTitle"
items:
item:
title: "first item"
description: "a random description"
item:
title: "second item"
description: "another item description"
Run Code Online (Sandbox Code Playgroud)
视图:
<%= t('front_page.index.description_section.items')do |item| %>
<%= item.title %>
<%= item.description %>
<%end %>
Run Code Online (Sandbox Code Playgroud)
结果:
{:item=>{:title=>"second item", :description=>"another item description"}}
Run Code Online (Sandbox Code Playgroud)
期望的结果:
first item
a random description
second item
another item description
Run Code Online (Sandbox Code Playgroud) 在Eclipse CDT中,我有几种构建配置。我想一次构建它们。它们可以并行或串行构建,没关系,没有依赖关系。我正在寻找的是一键式构建,它将通过一个动作重新编译所有构建配置。
是否有OS X/iOS CoreData的.NET C#版本?我正在阅读这篇文章,但它需要用于C#.NET.
在我构建的引擎中,我有 3 个类:书籍、类别和作者。每个类的迁移如下。作者和书籍之间以及类别和书籍之间存在一对多的关系。引擎将每个类命名为book_store
. 在 Postgresql(而不是 sqlite)上使用相同的迁移时,我收到一个错误,其中一个类不存在PG::UndefinedTable: ERROR: relation "authors" does not exist
我不确定为什么会发生这个错误。命名空间也应该在引用中吗?例如,从此:
t.references :author, index: true, foreign_key: true
t.references :category, index: true, foreign_key: true
Run Code Online (Sandbox Code Playgroud)
对此:
t.references :book_store_author, index: true, foreign_key: true
t.references :book_store_category, index: true, foreign_key: true
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用,因为BookStore::Books
命名book_store_author
和book_store_category
结果中会有一个属性BookStore::Books.book_store_author
,该属性不会正确地作用于引擎。
我是否可能需要更改迁移代码以在单独的行上反映引擎的命名空间?
# This migration comes from book_store (originally 20150814153615)
class CreateBookStoreAuthors < ActiveRecord::Migration
def change
create_table :book_store_authors do |t|
t.string :name
t.text :description
t.string :slug
t.timestamps …
Run Code Online (Sandbox Code Playgroud) 如何通过 curl 发布以将文件(在这种情况下为图像)上传到活动存储?文档没有确切说明如何使用 curl 或 JS(例如 Axios)
像这样的工作(如果我关闭真实性令牌(skip_before_action :verify_authenticity_token
)):
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X POST -d '{"image": {"user_id":"1"}}' http://localhost:3000/images.json
Run Code Online (Sandbox Code Playgroud)
这将像正常的 curl JSON 请求一样按预期发布。
像这样用 base64 编码文件看起来很有希望:
(echo -n '{"image": {"user_id":"1", "picture":"'; base64 /Users/cj/Desktop/DesktopArchive/5vvyo4u8y8wz.jpg; echo '"}}') | curl -v -H "Content-Type: application/json" -H 'Accept: application/json' -X POST -d @- http://localhost:3000/images.json
Run Code Online (Sandbox Code Playgroud)
虽然我ActiveSupport::MessageVerifier::InvalidSignature
在上传中得到了一个。我怀疑 base64 不是正确的签名。我应该使用什么来编码要上传到活动存储的图像?
编辑:
不是通过 JSON,而是通过表单工作:
curl \
-F "image[user_id]=1" \
-F "image[picture]=@/Users/cj/Desktop/DesktopArchive/5vvyo4u8y8wz.jpg" \
http://localhost:3000/images
Run Code Online (Sandbox Code Playgroud)
但是,您如何通过 json 调用来完成它,以便它可以通过 Axios 或其他方式完成?
esl-erlang
我正在尝试在 Ubuntu 20.04 docker 映像上安装 Erlang/Elixir,但我被有关地理区域的提示挂断了。如何静音或设置默认值US
?
这是我的 Docker 镜像:
FROM ubuntu:20.04
ENV LANG=en_US.UTF-8
RUN apt-get update -y
RUN apt-get install -y wget gnupg2 inotify-tools locales && \
locale-gen en_US.UTF-8
RUN wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && dpkg -i erlang-solutions_2.0_all.deb
RUN apt-get update -y
RUN apt-get install -y esl-erlang
RUN apt-get install -y elixir
CMD ["/bin/bash"]
Run Code Online (Sandbox Code Playgroud)
下面是docker挂掉的提示:
cjsMBP15:ubunutu-elixir cj1$ docker build -t ubuntu-elixir .
[+] Building 124.8s (9/11)
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 532B …
Run Code Online (Sandbox Code Playgroud) 当我在image_tag中包含可选标记时,它会抛出一个错误:
undefined local variable or method `src' for #<#<Class:0x007fa143339230>:0x007fa147942998>
Run Code Online (Sandbox Code Playgroud)
原始HTML(或所需)
<img src="dark-logo.png" data-src="dark-logo.png" data-src-retina="logo-retina.png" width="244" height="56" alt="">
Run Code Online (Sandbox Code Playgroud)
Rails视图
<%= image_tag "dark-logo.png", data-src => "dark-logo.png %>
Run Code Online (Sandbox Code Playgroud)
如何获取image_tag中的可选标签以呈现所需的HTML?
我在生产时从根路径上的某些IP地址随机获取此错误.rails应用程序不支持格式,:formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword"]
因此如果正在为它们发出请求,则可能会出现此错误.我猜测有人或某个机器人试图对网站进行攻击 - 我如何将这些类型的请求重定向或路由回路径路径,以免产生错误?
ActionView::MissingTemplate: Missing template front_page/index, application/index with {:locale=>[:en], :formats=>[:gif, "image/x-xbitmap", :jpeg, "image/pjpeg", "application/x-shockwave-flash", "application/vnd.ms-excel", "application/vnd.ms-powerpoint", "application/msword"], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :jbuilder]}. Searched in:
* "/app/app/views"
* "/app/vendor/bundle/ruby/2.0.0/gems/activeadmin-1.0.0.pre2/app/views"
* "/app/vendor/bundle/ruby/2.0.0/gems/kaminari-0.16.3/app/views"
* "/app/vendor/bundle/ruby/2.0.0/gems/devise-3.5.2/app/views"
File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/path_set.rb", line 46, in find
File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/lookup_context.rb", line 121, in find
File "/app/vendor/bundle/ruby/2.0.0/gems/actionview-4.2.4/lib/action_view/renderer/abstract_renderer.rb", line 18, in find_template
Run Code Online (Sandbox Code Playgroud)
完整的错误在这里
我有一个时间序列数据,其中我试图在特定时间间隔内按顺序查找连续的记录条纹,并按每个连续记录系列进行分组。例如,如果每个集合(组)的记录之间的时间间隔为 5 分钟,则 5 分钟内的任何下一条记录都将包含在该集合中,并且任何超过 5 分钟的记录都将结束该集合(组)。接下来的两个记录将在 5 分钟内出现一个新的集合(组)。
**分钟分隔不在表中,是在查询中计算的
| | | | | |
|----|---------------------|-----------------------------------|----------|------------------------------------------------------------|
| id | timestamp | minute separation (Calculated **) | group | notes |
| 1 | 2018-02-13T01:18:00 | 0 | Group 1 | |
| 2 | 2018-02-13T01:22:00 | 4 | Group 1 | |
| 3 | 2018-02-13T01:25:00 | 3 | Group 1 | |
| 4 | 2018-02-13T01:31:00 | 6 | No Group | breaks group 1 |
| 5 …
Run Code Online (Sandbox Code Playgroud) elixir ×2
postgresql ×2
.net ×1
build ×1
c# ×1
core-data ×1
curl ×1
docker ×1
eclipse ×1
eclipse-cdt ×1
ecto ×1
erlang ×1
image ×1
rails-i18n ×1
sql ×1
ubuntu ×1
ubuntu-20.04 ×1