相关疑难解决方法(0)

除了XHTML自包含标记之外,RegEx匹配开放标记

我需要匹配所有这些开始标记:

<p>
<a href="foo">
Run Code Online (Sandbox Code Playgroud)

但不是这些:

<br />
<hr class="foo" />
Run Code Online (Sandbox Code Playgroud)

我想出了这个,并希望确保我做对了.我只抓住了a-z.

<([a-z]+) *[^/]*?>
Run Code Online (Sandbox Code Playgroud)

我相信它说:

  • 找一个小于,然后
  • 然后,查找(并捕获)az一次或多次
  • 然后找到零个或多个空格
  • 找到任何字符零次或多次,贪婪/,然后
  • 找到一个大于

我有这个权利吗?更重要的是,你怎么看?

html regex xhtml

1323
推荐指数
36
解决办法
270万
查看次数

Rails:即使不需要,也可以在连接上使用.references

我知道当你使用includeswhere在连接表上指定一个子句时,你应该使用.references

例:

# will error out or throw deprecation warning in logs
customers = Customer.includes(:orders).where("Orders.cost < ?", 100)
Run Code Online (Sandbox Code Playgroud)

否则,在rails 4或更高版本中,您将收到如下错误:

Mysql2 ::错误:'where子句'中的未知列'Orders.cost':SELECT customers.*FROM customersWHERE(Orders.cost <100)

或者您将收到弃用警告:

弃用警告:您似乎急于加载在字符串SQL片段中引用的表(用户,地址之一).例如:

Post.includes(:comments).where("comments.title = 'foo'")
Run Code Online (Sandbox Code Playgroud)

目前,Active Record识别字符串中的表,并且知道将comments表连接到查询,而不是在单独的查询中加载注释.但是,在不编写完整的SQL解析器的情况下执行此操作本身就存在缺陷.由于我们不想编写SQL解析器,因此我们将删除此功能.从现在开始,当您从字符串引用表时,必须明确告诉Active Record:

Post.includes(:comments).where("comments.title ='foo'").references(:comments)

如果您不依赖隐式连接引用,则可以通过设置完全禁用该功能config.active_record.disable_implicit_join_references = true.(

SELECT"users"."id"AS t0_r0,"users"."name"AS t0_r1,"users"."email"AS t0_r2,"users"."created_at"AS t0_r3,"users"."updated_at"AS t0_r4 ,"地址"."id"AS t1_r0,"地址"."user_id"AS t1_r1,"地址"."country"AS t1_r2,"地址"."street"AS t1_r3,"地址"."postal_code"AS t1_r4 ,"地址"."city"AS t1_r5,"地址"."created_at"AS t1_r6,"地址"."updated_at"AS t1_r7 FROM"users"LEFT OUTER JOIN"地址"ON"地址"."user_id"="用户"."id"WHERE(addresses.country ='Poland')

说得通.使用时,Rails不希望成为SQL解析器includes.因此,为了让铁路开心,我们这样做:

# No error and no deprecation warning because we are …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails

3
推荐指数
1
解决办法
2355
查看次数

标签 统计

html ×1

regex ×1

ruby ×1

ruby-on-rails ×1

xhtml ×1