使用时,Rails 4引入了弃用警告:uniq => true with has_many:through.例如:
has_many :donors, :through => :donations, :uniq => true
Run Code Online (Sandbox Code Playgroud)
产生以下警告:
DEPRECATION WARNING: The following options in your Goal.has_many :donors declaration are deprecated: :uniq. Please use a scope block instead. For example, the following:
has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'
should be rewritten as the following:
has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'
Run Code Online (Sandbox Code Playgroud)
重写上述has_many声明的正确方法是什么?
activerecord ruby-on-rails ruby-on-rails-4 rails-activerecord
Rails 5.0.0.beta4在包含dynamic:action和:controller segments的路由上引入了弃用警告:
DEPRECATION WARNING: Using a dynamic :action segment in a route is deprecated and will be removed in Rails 5.1.
Run Code Online (Sandbox Code Playgroud)
来自此PR的提交消息指出:
允许:controller和:通过config/routes.rb中的路径指定的操作值一直是Rails中导致安全性发布的许多问题的根本原因.鉴于此,最好将控制器和操作明确列入白名单,而不是试图将"坏"值列入黑名单或消毒.
你会如何将一组动作参数"列入白名单"?我的路由文件中有以下内容,它们提出了弃用警告:
namespace :integrations do
get 'stripe(/:action)', controller: 'stripe', as: "stripe"
post 'stripe/deactivate', controller: 'stripe', action: 'deactivate'
end
Run Code Online (Sandbox Code Playgroud) 如何从rails generate命令生成模型,指定uuid主键的列类型?
我的目标是发出如下命令:
rails g model widget id{uuid}
Run Code Online (Sandbox Code Playgroud)
生成类似的迁移
create_table :widgets, id: :uuid do |t|
t.timestamps null: false
end
Run Code Online (Sandbox Code Playgroud)
我意识到我可以id: :uuid在生成迁移后添加,但我觉得必须有一些懒惰的方法来做到这一点。
我有Category表和Issue表.
在分类模型中:
has_many :issues
Run Code Online (Sandbox Code Playgroud)
在问题模型中:
belongs_to :category
Run Code Online (Sandbox Code Playgroud)
我能够编写一个查询,将query_count作为集合的虚拟属性返回:
Category.left_outer_joins(:issues).select('categories.*, COUNT(issues.*) AS issues_count').group('categories.id')
Run Code Online (Sandbox Code Playgroud)
但是,我希望表上的实际列将issues_count存储为表中的值categories,如下所示:
id | name | created_at | updated_at | description | tags | issues_count
Run Code Online (Sandbox Code Playgroud) 鉴于此无序列表:
<ul>
<li>Level One Item One
<ul>
<li>Level One Item One</li>
<li>Level One Item Two</li>
</ul>
</li>
<li>Level One Item Two
<ul>
<li>Level Two Item One</li>
<li>Level Two Item Two</li>
</ul>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
...我想将样式应用于a的所有直接<li>子节点<ul>,而不将该样式应用于嵌套列表项.
我认为这个CSS选择器会起作用,但它没有效果:
ul>li:not(li>ul>li) {
border: 1px solid red;
}
Run Code Online (Sandbox Code Playgroud)
这是一个小提琴:
开个玩笑,这里是小提琴:https://jsfiddle.net/nz5fdnd0/1/
以下是所需结果的图片:
所需的解决方案将避免在HTML中使用显式的class或id属性.