使用rails 3样式我怎么写相反的:
Foo.includes(:bar).where(:bars=>{:id=>nil})
Run Code Online (Sandbox Code Playgroud)
我想找到id为非null的地方.我试过了:
Foo.includes(:bar).where(:bars=>{:id=>!nil}).to_sql
Run Code Online (Sandbox Code Playgroud)
但那回归:
=> "SELECT \"foos\".* FROM \"foos\" WHERE (\"bars\".\"id\" = 1)"
Run Code Online (Sandbox Code Playgroud)
这绝对不是我需要的,而且几乎看起来像是ARel中的一个错误.
t.references和之间有什么区别t.belongs_to?为什么我们有这两个不同的词?在我看来他们做同样的事情?试过一些谷歌搜索,但没有找到解释.
class CreateFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.references :bar
t.belongs_to :baz
# The two above seems to give similar results
t.belongs_to :fooable, :polymorphic => true
# I have not tried polymorphic with t.references
t.timestamps
end
end
end
Run Code Online (Sandbox Code Playgroud) 我希望能够在rails中翻译i18n中的复数字符串.一个字符串可以是:
You have 2 kids
Run Code Online (Sandbox Code Playgroud)
要么
You have 1 kid
Run Code Online (Sandbox Code Playgroud)
我知道我可以使用复数辅助方法,但我希望将其嵌入到i18n翻译中,以便我在将来的任何时候都不必弄乱我的观点.我读到它:count在某种程度上用于复数的翻译,但我找不到任何关于它如何实现的真实资源.
请注意,我知道我可以在翻译字符串中传递变量.我也试过类似的东西:
<%= t 'misc.kids', :kids_num => pluralize(1, 'kid') %>
Run Code Online (Sandbox Code Playgroud)
哪个工作正常,但有一个相同想法的根本问题.我需要'kid'在pluralize helper中指定字符串.我不想这样做,因为它将导致将来查看问题.相反,我想保留翻译中的所有内容,而不是视图中的任何内容.
我怎样才能做到这一点 ?
ruby-on-rails internationalization pluralize plural rails-i18n
我在这个问题上挣扎了很长一段时间。在移动设备(Android 和 iOS)上可以看到此问题,某些设备可能需要稍微放大。在 PC 上,我也可以在切换到移动模式时在 Chrome 浏览器上重现此错误。以下是用于重现该错误的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
.top {
height: 100px;
background-color: #553213;
}
.middle {
height: 100px;
background-color: #553213;
}
.bottom {
height: 100px;
background-color: #553213;
}
</style>
</head>
<body>
<div style="width:300px; height: 300px">
<div class="top"></div>
<div class="middle"></div>
<div class="bottom"></div>
</div>
</body>
</html>Run Code Online (Sandbox Code Playgroud)
预期的结果将是一个 div,它的颜色为 #553213。但是,在某些移动设备上,它们会在这三个 div 之间显示额外的线条(或间隙)。
我的 iPhone
在我的 PC 上,使用带移动模式的 Chrome 浏览器
有谁知道这里发生了什么?任何关于它如何发生以及如何修复它的想法都将不胜感激。
我加入了一个使用 bundler 版本 1.17.1 的项目。目前我的系统使用的是 bundler 2.0.2 。有什么方法可以让我指定一个 bundler 版本,就像用rbenv. 喜欢的东西:
bundler --global 1.17.1
Run Code Online (Sandbox Code Playgroud)
这样,当我运行命令时,bundler -v我将收到结果1.71.1而不是2.0.2
我尝试卸载当前的捆绑器gem uninstall bundler并收到此消息:
$ gem uninstall bundler
Select gem to uninstall:
1. bundler-1.17.1
2. bundler-1.17.3
3. bundler-2.0.2
4. All versions
>
Run Code Online (Sandbox Code Playgroud)
这让我觉得有一种方法可以让我使用多个捆绑程序版本。任何仅用于指向我应该查找的位置的线索都将不胜感激。
我试过了bundle _1.17.1_ --version,但没有按我预期的那样工作
$ bundler -v
Bundler version 2.0.2
$ bundle _1.17.1_ --version
Bundler version 1.17.1
$ bundler -v
Bundler version 2.0.2
Run Code Online (Sandbox Code Playgroud)
预期:捆绑程序版本 1.17.1
实际: Bundler 版本 2.0.2
开关组件蓝图(此处为演示和文档)在选择/取消选择时不显示边框。我将这个组件包含在一个 React 组件中,如下所示:
import {Component} from "react";
import {Switch} from "@blueprintjs/core";
import React from "react";
class BPrintMain extends Component{
render(){
return (
<Switch id="switch-input-3" label="Public" disabled={false} />
)
}
}
export {BPrintMain};
Run Code Online (Sandbox Code Playgroud)
当我单击开关组件时,它会显示如下边框:
边框会一直保持,直到失去焦点,也就是我点击了页面上的其他东西。
我包括来自我的主要组件的 css 的 Blueprint css 文件,如下所示:
@import "~@blueprintjs/core/lib/css/blueprint.css";
@import "~normalize.css";
@import "~@blueprintjs/icons/lib/css/blueprint-icons.css";
Run Code Online (Sandbox Code Playgroud)
css 似乎适用于按钮、输入控件等。我缺少什么?为什么开关在焦点上显示焦点/边界框?
我是 ReactJS 的初学者,也是 NodeJS 的初学者。我很想知道为什么我们必须安装 NodeJS 运行 ReactJS 应用程序,因为 ReactJS 是客户端脚本。
我需要您的帮助,以更好地了解ReactJS的ref机制。我制作了一个自定义组件,并试图通过ref调用此组件的方法。但是,我得到这个错误,即我所调用的不是函数
我的自定义组件“ CountryInput”中有一个“ sayHi”方法,仅在console.log中显示“ hi”
class CountryInput extends React.Component {
sayHi(){
console.log('hi');
}
render() {
return(
<h1>hello</h1>
);
}
};
Run Code Online (Sandbox Code Playgroud)
这是我在其中使用ref的组件:
class MyComponent extends Component {
constructor(props) {
super(props);
this.countryRef = React.createRef();
}
save(){
this.countryRef.current.sayHi();
}
render() {
const {address, classes}= this.props;
return (
<React.Fragment>
<CountryInput ref={this.countryRef} />
<Button className={classes.button} onClick={()=>this.save()}>
Enregister
</Button>
</React.Fragment>
);
}
Run Code Online (Sandbox Code Playgroud)
当我单击按钮时,出现此错误:
“ TypeError:this.ref.current.sayHi不是函数”
我真的不明白为什么。你能帮助我吗?
有时我会进行嵌套破坏,这意味着不仅仅是一个级别,它可能很危险,但我只确保该属性存在,否则我将拥有undefined error的属性。
我最近做了这个,
const {
match: {
params: { id: UserId }
},
match
} = this.props
Run Code Online (Sandbox Code Playgroud)
我怀疑是否是好的代码。我需要match.params.id,我也需要match对象,所以这个重复的“变量”可以吗?
我想了解为什么反应会这样。
这有效
class Feed extends React.Component {
constructor(props) {
super(props);
}
render() {
const posts = [{ id: 1, title: 'post-1' }, { id: 2, title: 'post-2' }];
return (
<>
{posts.map(post => (
<Post key={post.id} title={post.title} />
))}
</>
Run Code Online (Sandbox Code Playgroud)
但这并不
class Feed extends React.Component {
constructor(props) {
super(props);
}
render() {
const posts = [{ id: 1, title: 'post-1' }, { id: 2, title: 'post-2' }];
return (
<>
{posts.map(post => {
// changes are here
if (post.id < …Run Code Online (Sandbox Code Playgroud) reactjs ×5
javascript ×3
arel ×1
bundler ×1
css ×1
ecmascript-6 ×1
html ×1
node.js ×1
plural ×1
pluralize ×1
rails-i18n ×1
ruby ×1
rubygems ×1