• Rails 5.2 新功能详解 at 2019年11月15日

    @lyfi2003 rails5.2 中 lock! 的机制有变化,导制以前正常的代码,时不时的出现(不是每次都出现),以什么办法兼容吗

    RuntimeError (Locking a record with unpersisted changes is not supported. Use `save` to persist the changes, or `reload` to discard them explicitly.)
    
  • @jasl 嗯,我刚也试了,在 5.2 下正常,感谢🍻

  • @jasl 我的 ruby 版本是 2.5.1 rails5.0.7.2

  • @jasl 用的是 role_core,和你 dummy 唯一不同的地方就是我没用 cancancan

    def create
        @role = Role.new(role_params)
    
        if @role.save
          redirect_to roles_url, notice: "Role was successfully created."
        else
          render :new
        end
      end
    
    # Only allow a trusted parameter "white list" through.
      private def role_params
        params.require(:role).permit(:name, permissions_attributes: {})
      end
    
  • @jasl 照着你的那个例子自己写的

  • @jasl 这样编辑权限的时候好像没生效

    Parameters: {"utf8"=>"✓", "authenticity_token"=>"w0o9CGy+oR9bqZaPpmglcNnKrzRS+e7/LFTZOPePAOWrHHwbuMABqzolmhB3u0vVUSRSPqs77BwKHKU8iObC+Q==", "role"=>{"name"=>"j", "permissions_attributes"=>{"task"=>{"create"=>"1", "destroy"=>"0", "update"=>"0", "update_my_own"=>"1", "destroy_my_own"=>"1"}, "production"=>{"create"=>"1", "destroy"=>"0", "accept"=>"0", "read"=>"1", "read_public"=>"0"}, "topic"=>{"create"=>"1", "destroy"=>"1", "accept"=>"1"}}}, "commit"=>"Update Role", "id"=>"7"}
      Role Load (0.5ms)  SELECT  `roles`.* FROM `roles` WHERE `roles`.`type` IN ('Role') AND `roles`.`id` = 7 LIMIT 1
    Query Trace:
          app/controllers/roles_controller.rb:47:in `set_role'
    Unpermitted parameters: task, production, topic
       (0.9ms)  BEGIN
      SQL (2.0ms)  UPDATE `roles` SET `permissions` = NULL, `updated_at` = '2019-11-11 16:52:40' WHERE `roles`.`id` = 7
    Query Trace:
          app/controllers/roles_controller.rb:32:in `update'
       (2.8ms)  COMMIT
    
  • @jasl 这个地方参数要怎么设置,手动一个一个指定吗?

    # Only allow a trusted parameter "white list" through.
      private def role_params
        params.require(:role).permit(:name, permissions_attributes: {})
      end
    
  • 下单成功,等待签收😀 😀

  • 还是运动好,跑步半年,完全没有控制饮食,瘦了十二斤

67325622