我正在开发一个项目,我们不会使用ajax调用来提交表单,所以我需要local: true在项目中输入每个表单,如rails docs中所示:
:local - By default form submits are remote and unobstrusive XHRs. Disable remote submits with local: true.
有没有办法默认将local选项设置为true?
我们正在使用这样的Rails 5 form_with助手:
<%= form_with(model: @user, local: true) do |f| %>
<div>
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div>
<%= f.label :email %>
<%= f.email_field :email %>
</div>
<%= f.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud) 我需要一项服务来从Amazon S3下载excel文件,然后使用node-xlsx进行解析
问题是我无法让xlsx解析文件。当我尝试回读刚写的文件时,代码中找不到该文件。
我不确定这是否是最好的方法,但这是我到目前为止得到的:
router.get('/process', (req, res) => {
var fileName = 'https://some-bucket.s3.amazonaws.com/some-excel-file.xlsx'
https.get(fileName, response => {
var body = ''
response.on('data', chunk => body += chunk)
response.on('end', () => {
//fs is being imported early on this file
fs.writeFile(__dirname + '/test.xlsx', body)
var f = fs.createReadStream(__dirname + '/test.xlsx')
var book = xlsx.parse(f)
book.forEach(sheet => console.log('sheet', sheet.name) )
res.status(200)
})
.on('error', e => {
res.status(500)
})
})
return
})
Run Code Online (Sandbox Code Playgroud) 我在 parse.com 上托管了这个结构:
事件
String Pointer<Player>Pointer<Match>匹配
String StringDate我想使用 REST 检索与一场特定比赛相关的所有事件,但我使用的查询有问题。
这是我正在使用的查询(带有 HTTParty gem 的 ruby):
base_uri = "https://api.parse.com/1/classes"
endpoint = 'Event/?&include=matchId&where={"ownerId":"201"}'
app_id = "app_id"
rest_api_key = "api_key"
headers = {"X-Parse-Application-Id" => app_id,
"X-Parse-REST-API-Key" => rest_api_key,
"Content-Type" => "application/json"}
response = HTTParty.get(URI.encode("#{base_uri}/#{endpoint}"), headers: headers)
Run Code Online (Sandbox Code Playgroud) 例如,给定一个具有sold_out属性的产品列表,我想更新该集合中每个项目的字段。
在这个特定的示例中,假设我想sold_out = false将该字段设置为该字段设置为的所有项目true:
Product.where({sold_out: true})
.fetchAll()
.then(soldOutCollection => {
return Promise.all(product => {
return product.save({sold_out: false})
})
})
Run Code Online (Sandbox Code Playgroud)
此方法有效,但它会触发集合中每个项目一个查询。
有没有办法一次更新所有项目(仅触发一个查询)?
PS:我试图避免直接使用knex.js
我正在使用Rails 3和MySQL数据库,我需要以编程方式创建这样的查询:
select * from table where category_name like '%category_name_1%'
OR category_name like '%category_name_2%'
(...snip...)
OR category_name like '%category_name_n%'
Run Code Online (Sandbox Code Playgroud)
鉴于表格大小和项目范围(我认为最多500行),我觉得使用像思考sphinx这样的东西会有点过分.我知道我可以通过直接编写查询字符串来完成此操作,但想知道是否有ActiveRecord方法来执行此操作.在官方指南中没有提到这一点,我现在谷歌搜索了很长一段时间,只是空手而归:(
另外,有没有理由(可能是Rails的原因?)不包含OR子句?
谢谢!