我有一个配方模型,其中包含很多成分,每种成分都属于一个项目.在我的高级搜索表单中,我希望用户选择多种成分,让Ransack找到包含用户选择的所有成分的配方.
我尝试了以下搜索字段:
= f.collection_select(:ingredients_item_id_in, Item.all, :id, :name, {}, {multiple: true})
Run Code Online (Sandbox Code Playgroud)
但从逻辑上讲,这会导致显示的所有配方都含有任何选定的成分.
由于一条记录不能包含多个item_id值,因此更改:ingredients_item_id_in为:ingredients_item_id_in_all不正确的查询结果.
有关在Ransack中创建此搜索参数的任何想法,还是应该为此创建子查询?
根据要求,我的控制器搜索方法:
def search
@q = Recipe.ransack(params[:q])
@recipes = @q.result(distinct: true).include_related_models.published
end
Run Code Online (Sandbox Code Playgroud) 我正在构建一个Geocoding类,它可以利用多个Web服务进行地理编码(即Google,Yahoo,Bing等).我试图以一种可以轻松配置新的Web服务的方式来实现它.大多数web服务返回XML/JSON ..对于PHP我选择XML作为我的主要焦点.所有代码都已到位,但现在Google返回以下XML(转换为simple_xml_element)
SimpleXMLElement Object
(
[status] => OK
[result] => Array
(
[0] => SimpleXMLElement Object
(
[type] => postal_code
[formatted_address] => 1010 Lausanne, Switzerland
[address_component] => Array
(
[0] => SimpleXMLElement Object
(
[long_name] => 1010
[short_name] => 1010
[type] => postal_code
)
[1] => SimpleXMLElement Object
(
[long_name] => Lausanne
[short_name] => Lausanne
[type] => Array
(
[0] => locality
[1] => political
)
)
[2] => SimpleXMLElement Object
(
[long_name] => Vaud
[short_name] => VD
[type] => …Run Code Online (Sandbox Code Playgroud) I have a domain registered on Route 53. This domain points towards some name servers of an old Route53 route. I'm now building my Terraform script to create a new Route53 zone. Is it possible to set the name servers when creating this? I tried the following, but that didn't work:
resource "aws_route53_record" "dev-ns" {
zone_id = "${aws_route53_zone.main.zone_id}"
name = "dev.example.com"
type = "NS"
ttl = "30"
records = [
"ns1.aws",
"ns2.aws",
"ns3.aws",
"ns4.aws",
]
}
Run Code Online (Sandbox Code Playgroud)
I could imagine that …
我已经为添加了自己产品的店主设置了magento装置.Unfortunataly他不了解URl的关键领域.当他复制产品时,每个产品现在都有相同的URL,增加的数字为/product-1234.html,下一个为/product-1235.html.由于他有近2k的产品,手动调整所有url键是一件麻烦事.有没有办法在magento(或直接在DB)清除这一点而不破坏商店.似乎如果我删除一个URL-key magento自动生成一个,这对我来说很好.
编辑:好的,所以我发现如何通过清除数据库表(catalog_product_entity_varchar)中的某些字段来重置URL密钥,但现在我需要Magento使用产品名称创建新的字段.有任何想法吗?
谢谢.
我有一个使用以下配置的应用程序:
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
config.time_zone = 'Amsterdam'
config.active_record.default_timezone = :utc
end
Run Code Online (Sandbox Code Playgroud)
我为用户提供了一个表单,要求一个单独的日期(日期选择器)和时间字段(下拉列表)。在before方法上,我将日期和时间连接到单个datetime字段中。似乎Time对象在某种程度上是UTC,而Date对象却不在乎。
当将其存储到数据库中时,时区会以某种方式得到纠正,但是时间会减少2个小时。这是由于时间仍在UTC上吗?我该如何以尊重日光节约的方式对此进行补偿?
代码样例
表格:
= simple_form_for @report do |f|
.row
.col.s6
= f.association :report_category
.col.s6
= f.association :account
.row
.col.s6.l4
= f.input :day, as: :string, input_html: {class: 'datepicker current-date'}
.col.s6.l4
= f.input :time, as: :string, input_html: {class: 'timepicker current-date'}
Run Code Online (Sandbox Code Playgroud)
模型中的回调
def create_timestamp
self.date = day.to_datetime + time.seconds_since_midnight.seconds
end
Run Code Online (Sandbox Code Playgroud)
保存后,我在表单中选择的时间相差2小时。
这是创建新记录后的样子,其中时间与创建记录的时间相同,以了解两者之间的区别:
date: Sat, 20 May 2017 16:10:00 CEST +02:00,
created_at: …Run Code Online (Sandbox Code Playgroud) 我在 Excel 中有一个表,我在其中添加了一行。然后,我引用该行并能够使用数字在列中存储值。
Dim table As ListObject
Dim lastRow As Range
Set table = sheet.ListObjects.Item("TagTable")
table.ListRows.Add
Set lastRow = table.ListRows(table.ListRows.Count).Range
lastRow(1) = "Value for column 1"
lastRow(2) = "Value for 2"
Run Code Online (Sandbox Code Playgroud)
问题是它不太灵活。我宁愿解决列名称。我正在疯狂地搜索,但我找不到任何有关如何实现这一目标的信息。这是否可能,或者我是否用这段代码做了一些疯狂的事情?
我正在构建一个带有 Rails 后端的 Vue 应用程序。我正在关注一些在线文章,这些文章建议了一个工作流程,其中我:
前两个步骤工作正常,但我很难理解如何将文件数据包含在类型为“multipart/form-data”的请求中。
我的代码如下,我使用vuetify作为组件库:
<template>
<v-form>
<v-file-input v-model="file" label="File input"></v-file-input>
<v-btn class="mt-2" block bottom color="primary" @click="submit">Opslaan</v-btn>
</v-form>
</template>
<script>
import { axios_request } from '../_helpers';
export default {
name:'AccountImageForm',
data: () => ({
file: {}
}),
methods: {
filesChange(event) {
this.file = event.target.files[0]
},
submit() {
axios_request('/api/v1/images/upload_url')
.then(
response => {
// this response contains the pre-signed info
var data = {
...response.url_fields,
file: …Run Code Online (Sandbox Code Playgroud) 我想创建一个包含jQuery对象的JS数组,如下所示:
var oFormFields = new Object;
oFormFields.label = $(document.createElement('label'));
oFormFields.input = $(document.createElement('input'));
Run Code Online (Sandbox Code Playgroud)
由于这会导致我的代码崩溃,我希望这是不可能的.任何替代品?这是我的简化版本,我想包含一些其他属性,这样我就可以在构建动态表单时在我的代码中重用它.
编辑:看来这毕竟有用......我想做的是这样的:
var oFormFields = new Object;
oFormFields.name_field.label = $(document.createElement('label')).addClass('nam_field');
oFormFields.name_field.input = $(document.createElement('input')).addClass('nam_field');
Run Code Online (Sandbox Code Playgroud)
这确实打破了我的代码.我是jQuery的新手,来自PHP背景我有一些麻烦调整到使用数组/对象的正确方法.
我正在为模型范围编写一个非常简单的测试:
describe "scope tests" do
let(:account1) { create(:account, last_seen: Date.today)}
let(:account2) { create(:account, last_seen: Date.today - 4.days)}
let(:account3) { create(:account, last_seen: Date.today - 10.days)}
let(:d) { Date.today}
let(:seen_between) { Account.seen_between(d - 14.days, d - 2.days) }
it "response to seen_between" do
expect(seen_between).to eq([account3, account2])
expect(seen_between).to_not include(account1)
end
end
Run Code Online (Sandbox Code Playgroud)
但是我遇到了一些非常冗长的错误:
Failure/Error: expect(Account.all).to eq([account3, account2])
expected: [#<Account id: 2, date_of_birth: nil, description: nil, active: true, created_at: "2018-05-10 12:05:4..._lead_id: nil, account_category_id: nil, psychiatrisch: nil, oggz: nil, problem: nil, actions: nil>]
got: #<ActiveRecord::Relation [#<Account …Run Code Online (Sandbox Code Playgroud) amazon-s3 ×1
axios ×1
datetime ×1
excel ×1
google-maps ×1
javascript ×1
jquery ×1
magento ×1
php ×1
ransack ×1
rspec ×1
terraform ×1
vba ×1
vue.js ×1
vuetify.js ×1
web-services ×1
xml ×1