说到授权/认证设计+ cancan通常是我的首选宝石.在发布了Rails4强大的参数之后,我一直在研究使用cancan_strong_parameters gem.
我不能动摇这种方法看起来有点'hacky'的感觉.其他选项似乎是TheRole gem或者只是从头开始编辑我自己的身份验证.
希望在这里有第一手经验的人可以就他们如何解决问题,面临的问题以及每种方法的不足之处(如果有的话)提出一些指示.
我知道这不是一个干净的StackOverflow类型的问题,但谷歌搜索时似乎没有太多关于这个主题的信息.谢谢.
目前,Item 属于一个公司并且has_many ItemVariants.
我正在尝试使用嵌套的fields_for通过Item表单添加ItemVariant字段,但是使用:item_variants不显示表单.它仅在我使用单数时显示.
我检查了我的关联,它们似乎是正确的,它可能与项目嵌套在公司下面有关,还是我错过了其他的东西?
提前致谢.
注意:下面的代码段中省略了不相关的代码.
编辑:不知道这是否相关,但我正在使用CanCan进行身份验证.
的routes.rb
resources :companies do
resources :items
end
Run Code Online (Sandbox Code Playgroud)
item.rb的
class Item < ActiveRecord::Base
attr_accessible :name, :sku, :item_type, :comments, :item_variants_attributes
# Associations
#-----------------------------------------------------------------------
belongs_to :company
belongs_to :item_type
has_many :item_variants
accepts_nested_attributes_for :item_variants, allow_destroy: true
end
Run Code Online (Sandbox Code Playgroud)
item_variant.rb
class ItemVariant < ActiveRecord::Base
attr_accessible :item_id, :location_id
# Associations
#-----------------------------------------------------------------------
belongs_to :item
end
Run Code Online (Sandbox Code Playgroud)
项目/ new.html.erb
<%= form_for [@company, @item] do |f| %>
...
...
<%= f.fields_for :item_variants do |builder| %>
<fieldset>
<%= …Run Code Online (Sandbox Code Playgroud) ruby ruby-on-rails nested-attributes fields-for ruby-on-rails-3
我目前正在研究Uudemy的ElasticSearch课程,但视频正在谈论ElasticSearch 5,我目前正在使用ElasticSearch 6.我无法将父/子关系转换为新格式.
在视频设置Franchise与Films(即Star Wars和The Jedi Returns分别.
导师做以下事情:
curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series" -d '
{
"mappings": {
"franchise": {},
"film": {
"_parent": {
"type": "franchise"
}
}
}
}'
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试添加映射时,我收到以下错误:
? Downloads curl -H "Content-Type: application/json" -XPUT "127.0.0.1:9200/series?pretty" -d '
{
"mappings": {
"franchise": {},
"film": {
"_parent": {
"type": "franchise"
}
}
}
}'
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "Rejecting mapping …Run Code Online (Sandbox Code Playgroud) (选择使用子句按字段对进行查询in)
我有一个哈希数组,如下所示:
[ {product_id: 7629, group_id: 4}, {product_id: 8202, group_id: 3} ]
我想返回的是Items表中与数组中的字段对匹配的所有记录。
在 SQL 中,它将像这样被检索:
SELECT *
FROM items
WHERE (product_id, group_id) IN (VALUES (7629,4), (8202,3))
Run Code Online (Sandbox Code Playgroud)
但我在使用 Rails 条款来做到这一点时遇到了麻烦.where。这可能吗?