在我的RoR应用程序中,我正在尝试创建一种方法,该方法将查看文本字段(正文),并在共享英国移动电话号码的情况下将消息发布到松弛状态。我正在通过搜索正文中任何地方出现的const obj_loader = new THREE.OBJLoader(),
mtl_loader = new THREE.MTLLoader();
// uses example of OBJ + MTL from three.js/examples
mtl_loader
.setTexturePath('bar/')
.setPath('bar/')
.load('floor.mtl', (materials) => {
materials.preload()
obj_loader
.setMaterials(materials)
setPath('bar/')
.load('floor.obj', (object) => {
// everything returns status 200!
// material is being applied but no texture
scene.add(object);
})
});
或'+447'来测试英国的手机号码。
07
当我尝试在localhost(例如rails)中启动应用程序时,这会出现以下错误:
def contact_details_shared
if self.body.include? '07' || self.body.include? '+447'
slack_post(self)
end
end
但是我在这里看不到任何语法问题。
所以我也尝试了以下
syntax error, unexpected tSTRING_BEG, expecting keyword_then or ';' or '\n'
当我尝试在localhost(例如rails)中启动应用程序时,这会出现以下错误:
def contact_details_shared
if ( self.body.include? '07' || self.body.include? '+447' )
slack_post(self)
end
end
对此我感到很惊讶,因为我的代码应该为每个OR条件返回一个布尔值(而不是字符串)。
那么...两个问题: 1)如何使代码正常工作? 2)我想有些解决方案比我的解决方案更优雅。建议非常欢迎!有什么想法吗?
答案 0 :(得分:2)
尝试:
if self.body.include?('07') || self.body.include?('+447')
我怀疑ruby需要使用括号来明确标识参数(即'07'
和'+447'
)。
答案 1 :(得分:0)
See this magic:
Ex: "hello07".include? '07'
return true
when you use
"hello07".include? '+441'
returns false
"hello07".include? '07' || "hello07".include? '+441'
SyntaxError: (irb):39: syntax error, unexpected tSTRING_BEG, expecting end-of-input
"hello07".include? '07' || "hello07".include? "+441"
^
if you use "or" instead of ||
"hello07".include?'07' or "hello07".include?'+447'
returns true
if you want to work your code, you can use
if self.body.include?('07') or self.body.include?('+447')
the solution is use "or" instead of "||"
if you want use the "||" use this syntax
if (self.body.include?'07') || (self.body.include?'+447')