在应用程序中,需要以用户的语言生成字符串,然后将其传递到另一个服务器/应用程序。因此该模型可以识别
def user_language
self.user.idioma.code.downcase
end
Run Code Online (Sandbox Code Playgroud)
但基于该语言生成一个字符串并读取语言环境的 yaml 文件是一个挑战:
def description
user_language.products.name
end
Run Code Online (Sandbox Code Playgroud)
我意识到该模型不知道去查找区域设置文件。怎样才能调用它呢?
class Accdist < ActiveRecord::Base
has_many :accdistlavoraziones, dependent: :destroy
Run Code Online (Sandbox Code Playgroud)
删除accdist时,控制台将输出以下内容:
Accdist Load (27.3ms) SELECT "accdists".* FROM "accdists" WHERE "accdists"."id" = $1 LIMIT 1 [["id", "1"]]
Accdistlavorazione Load (20.2ms) SELECT "accdistlavoraziones".* FROM "accdistlavoraziones" WHERE "accdistlavoraziones"."accdist_id" = 1
SQL (59.7ms) DELETE FROM "accdistlavoraziones" WHERE "accdistlavoraziones"."" = $1 [[nil, nil]]
PG::SyntaxError: ERROR: zero-length delimited identifier at or near """"
LINE 1: ...OM "accdistlavoraziones" WHERE "accdistlavoraziones"."" = $1
^
: DELETE FROM "accdistlavoraziones" WHERE "accdistlavoraziones"."" = $1
(0.1ms) ROLLBACK
Completed 500 Internal Server Error in …Run Code Online (Sandbox Code Playgroud) 将 webpacker 与 Rails 一起使用,编译过程会收到来自 babel 的更改配置问题的垃圾邮件
虽然向文件添加分辨率块的解决方案package.json+对最新版本的更新消除了这些消息的汤姆,但仍然有一些
Though the "loose" option was set to "false" in your @babel/preset-env config, it will not be used for @babel/plugin-proposal-private-methods since the "loose" mode option was set to "true" for @babel/plugin-proposal-class-properties.
The "loose" option must be the same for @babel/plugin-proposal-class-properties, @babel/plugin-proposal-private-methods and @babel/plugin-proposal-private-property-in-object (when they are enabled): you can silence this warning by explicitly adding
["@babel/plugin-proposal-private-methods", { "loose": true }]
to the "plugins" section of your Babel config.
Run Code Online (Sandbox Code Playgroud)
没那么有帮助。搜索config …
使用符号数组
> I18n.available_locales
[:en, :it, :fr, :de]
> I18n.locale
:en
Run Code Online (Sandbox Code Playgroud)
运行数组计算
> I18n.available_locales - I18n.locale
Run Code Online (Sandbox Code Playgroud)
返回错误:
TypeError (no implicit conversion of Symbol into Array)
Run Code Online (Sandbox Code Playgroud)
一个人无法对要计算的组件进行操作以将其转换为数组
> I18n.locale.to_a
NoMethodError (undefined method `to_a' for :en:Symbol)
Run Code Online (Sandbox Code Playgroud)
那么,如果最终目的是要执行什么计算方法?
<% I18n.inactive_locales.each do |locale| %>
<li><%= link_to locale.to_s, { locale: locale } %></li>
<% end %>
Run Code Online (Sandbox Code Playgroud) 以下_receipt_number部分(为简洁起见,删除了 HTML 格式标记)
<%= turbo_frame_tag :receipt_number do %>
<%= t('scan') %> <%= t('cart.receipt_number') %>
<h3><%= @cart.receipt_number %></h3>
<% if @cart.receipt_number %>
<%= button_to t('change'), clear_receipt_number_cart_path(id: @cart.id), class: 'button warning', method: :patch %>
<% end %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
在 HTML 中呈现为:
<turbo-frame id="receipt_number">
scan receipt number
<h3></h3>
</turbo-frame>
Run Code Online (Sandbox Code Playgroud)
通过控制设备摄像头的 javascript 运行并处理扫描(这是该实例的相关 javascript 代码)
let formData = new FormData();
let CodeParams = {
code_data: result.text,
id: <%= @cart.id %>
};
formData.append("code_json_data", JSON.stringify(CodeParams));
fetch("update_receipt_number", {
method: "post",
format: "turbo_stream",
body: …Run Code Online (Sandbox Code Playgroud) 通过pgdump将数据库从另一台服务器导入9.3.5安装,我在访问postgreSQL的命令行时遇到了一些错误.
例如:
sudo su - postgres
psql -d template1
Run Code Online (Sandbox Code Playgroud)
允许我查看用户\du到\list数据库,但如果我说,根据文档:
CREATE USER michaelrodent
Run Code Online (Sandbox Code Playgroud)
要么
CREATE ROLE donatoquack WITH LOGIN PASSWORD 'spltfrzspltrz'
Run Code Online (Sandbox Code Playgroud)
\du仅列出默认用户或角色.但是,如果我从bash提示符说明
sudo -u postgres createuser michaelrodent
Run Code Online (Sandbox Code Playgroud)
\du然后显示角色名称.愚蠢的我没有将角色属性分配给超级用户,因此当通过psql导入时,我收到的错误如下:
ERROR: must be owner of extension plpgsql
ERROR: must be owner of relation accbiadesivolumes
Run Code Online (Sandbox Code Playgroud)
回到postgres用户,我不能:
alter role michaelrodent with superuser
Run Code Online (Sandbox Code Playgroud)
...无法理解为什么postgresql命令语言无法注册以及如何使用sudo -u postgres [...]的快捷语法来改变角色......
生成以下错误 undefined method +' for #<Debit
控制器动作定义的位置
@debits = Debit.order("vatunitid ASC").where('unit_id = ? AND folio_id = ?', session[:unit_id], @folio.id).to_a
@adhoc_folios = Folio.order("created_at asc").where(['checkout IS NULL AND unit_id = ? AND id != ?', session[:unit_id], @folio.id]).all
@vatunits = Vatunit.where(['unit_id = ?', session[:unit_id]]).to_a
@rates = @debits.map(&:vatunitid).uniq
Run Code Online (Sandbox Code Playgroud)
目前在视图中(用于测试目的)
@rates.each do |rate|
@debits_for_rate = @debits.select{ |i| i.vatunitid == rate }
@debits_for_rate.count
@debits_for_rate.sum(:amount)
Run Code Online (Sandbox Code Playgroud)
count指令返回一个正确的值.
此时调用sum被认为是不存在的.
这是怎么发生的以及如何克服它?
使用硬编码数组
array = [30,29,31,13,10,12,6,7,8,9,11]
Run Code Online (Sandbox Code Playgroud)
尝试执行查询
@pick = Item.where('id IN (?)', array).to_a
Run Code Online (Sandbox Code Playgroud)
选择的 Items 的顺序如何保持初始数组的顺序?
使用红宝石功能,可以提取随机值
first_random = ["alt_1", "alt_2", "alt_3", "alt_4", "alt_5", "alt_6"].sample
Run Code Online (Sandbox Code Playgroud)
类属性是 alt_1, alt_2, alt_3, alt_4, alt_5, alt_6, name, created_at, updated_at
这些值表示类的属性。没有引号将它们标识为字符串AFAIK,就无法在数组中描述它们。目标是在视图中调用此随机属性。然而,
@text.first_random
Run Code Online (Sandbox Code Playgroud)
生成一个缺少错误的方法,因为ruby肯定会沿引号传递。
如何克服?
在 postgis 安装失败之后
CREATE EXTENSION PostGIS WITH SCHEMA postgis;
ERROR: could not open extension control file "/usr/local/Cellar/postgresql@9.5/9.5.12/share/postgresql@9.5/extension/postgis.control": No such file or directory
Run Code Online (Sandbox Code Playgroud)
在此页面上使用 psql 9.5.12 为 Mavericks 设置搜索合适的版本:
https://github.com/Homebrew/homebrew-core/commits/master/Formula/postgis.rb
Run Code Online (Sandbox Code Playgroud)
回来了
Sorry, this commit history is taking too long to generate.
Refresh the page to try again, or view this history locally using the following command:
git log master -- Formula/postgis.rb
Run Code Online (Sandbox Code Playgroud)
但那又回来了 fatal: bad revision 'master'
是否有另一种方法来查询历史记录(或根据其对 postgresql 版本的依赖性调用 postgis)?
在控制台中:
1.9.3p547 :010 > my_s = 00013.to_s
=> "11"
1.9.3p547 :011 > my_s = 00013.to_i
=> 11
1.9.3p547 :012 > 13.to_s
=> "13"
1.9.3p547 :013 > 13.to_i
=> 13
Run Code Online (Sandbox Code Playgroud)
为什么这种治疗方法不同?如何在基本数字但用零填充的字符串值之间进行比较?
根据官方文档
[1,2].product([3,4],[5,6])
=> [[1, 3, 5], [1, 3, 6], [1, 4, 5], [1, 4, 6], [2, 3, 5], [2, 3, 6], [2, 4, 5], [2, 4, 6]]
Run Code Online (Sandbox Code Playgroud)
返回所有数组中元素的所有组合的数组。
然而,
first_array = ["orange", "purple", "colour-black"]
other_arrays = [["sputter", "ribus"], ["incontinentia", "portia"]]
@end_array = first_array.product(other_arrays)
Run Code Online (Sandbox Code Playgroud)
返回,意外:
[["orange", ["sputter", "ribus"]], ["orange", ["incontinentia", "portia"]], ["purple", ["sputter", "ribus"]], ["purple", ["incontinentia", "portia"]], ["colour-black", ["sputter", "ribus"]], ["colour-black", ["incontinentia", "portia"]]]
Run Code Online (Sandbox Code Playgroud)
为什么 ruby 的行为不同?怎样做才能得到设计的结果?
ruby ×6
arrays ×1
babeljs ×1
git ×1
github ×1
postgresql ×1
rails-i18n ×1
turbo ×1
webpacker ×1