我有基于SQL和Java的迁移.我正在尝试使用Flyway回调挂钩在验证完成后立即执行其他操作,但它没有捕获此回调.从文档中,它看起来像下面这么简单.
这是我的文件结构:
-java
--db
---migrations
----V1__apple <----java based
--FruitShopFlywayCallback.java <---- Callback class
-resources
--migrations
--- V1__orange.sql <----sql based
Run Code Online (Sandbox Code Playgroud)
我的回调:
public class FruitShopFlywayCallback extends BaseFlywayCallback {
@Override
public void afterValidate(Connection dataConnection) {
System.out.println("it worksssssssss");
}
}
Run Code Online (Sandbox Code Playgroud)
我的想法是,一旦迁移完成,flyway就会回调这个方法.我不确定我错过了什么?
我正在尝试使用嵌套文件结构组织我的本地化文件,以便更容易查找.
我跟着
但我得到的翻译缺失:en.view.fruits.apple.我认为Rails试图只查找locales/en.yml文件中的翻译而不是子目录,尽管我已经将它们包括在内.
配置/ application.rb中:
config.i18n.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
Run Code Online (Sandbox Code Playgroud)
我的语言环境目录:
|locales
|-en.yml
|-views
|--en.yml
Run Code Online (Sandbox Code Playgroud)
区域设置/查看/ en.yml:
en:
fruits:
apple: "apple"
Run Code Online (Sandbox Code Playgroud)
意见/ fruit.html.haml:
= I18n.t('views.fruits.apple')
Run Code Online (Sandbox Code Playgroud) haml ruby-on-rails internationalization i18n-gem ruby-on-rails-4
我们的应用程序在 Rails 5.2 上运行,它使用 webpacker 为资产提供服务,而没有资产管道。我想知道在脚本标签上设置 nonce 属性的最佳方法是什么。
在 中content_security_policy.rb,有一个content_security_policy_nonce_generator用于 UJS,我想知道我是否仍然可以使用它而没有任何副作用。下面的工作,我只是想知道做这样的事情的最佳实践是什么。
#initializers/content_security_policy.rb
# If you are using UJS then enable automatic nonce generation
Rails.application.config.content_security_policy_nonce_generator = -> request { SecureRandom.base64(16)
Run Code Online (Sandbox Code Playgroud)
在 中application.html.erb,如果我想在 script 标签上有 nonce,我将不得不从请求中获取它。根据这里:https : //api.rubyonrails.org/classes/ActionDispatch/ContentSecurityPolicy/Request.html#method-i-content_security_policy_nonce
#app/views/layouts/application.html.erb
<!DOCTYPE html>
<html dir="ltr">
<head>
<title>FruitsMarket</title>
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_pack_tag 'application' %>
<%= javascript_pack_tag 'polyfills' %>
<%= javascript_pack_tag 'application' %>
<script type="text/javascript" nonce=<%= request.content_security_policy_nonce %>>
alert('hi');
</script>
</head>
<body>
<%= yield %> …Run Code Online (Sandbox Code Playgroud) 我在里面用'\n'得到这个字符串,我想显示一个新行,其中有'\n'而不是显示原始字符串
在fruits.description里面
fruits.description: 'This is an red apple \n It is also very sweet'
Run Code Online (Sandbox Code Playgroud)
我的渲染辅助方法
def get_description(fruits)
if fruits.type == 'apple'
haml_tag 'p', fruits.description, {id: fruits.id}
end
end
Run Code Online (Sandbox Code Playgroud)
我想要显示字符串,就像这样
This is an red apple
It is also very sweet
Run Code Online (Sandbox Code Playgroud) 我想知道我是否可以设置路由,以便带参数的show route转到另一个方法,当它没有参数时返回show方法.
get fruits/:id fruits#show
Run Code Online (Sandbox Code Playgroud)
和
get fruits/id?market=XXX fruits#market
Run Code Online (Sandbox Code Playgroud)
我想这样做,因为我想通过ajax重新加载该页面,我做了一个popstatus来添加该URL.用这种方式使这个工作很好
所以我正在使用正则表达式.所以我只想检测字符串是否包含任何数字.如果它匹配它.
Case 1 "abc" -> false
Case 2 "165-45" ->true
Case 3 "ab3b" -> true
Case 4 "1231asdf" -> true
Case 5 "asdfasd123213" -> true
Case 6 "12-465" -> true
Case 7 "ASDSAD" -> False
Run Code Online (Sandbox Code Playgroud)
到目前为止,我得到了但是第3和第4案失败了
if(query.matches("[0-9,-]+$")){
// contains a number
System.out.println("match");
} else{
// does not contain a number
System.out.println("not match");
}
Run Code Online (Sandbox Code Playgroud)